Hullo. Welcome to my question. In my controller I need to get the number of items in a table. If I was just using MySQL, I''d do "select count(*) from blah where blah blah blah". What is the way to do this in my controller? I''d like to avoid something like Blah.find(:all, :conditions => blah blah).size Is there a way to do the equivalent of select count(*) in the controller? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11 Dec 2008, at 16:05, Joe Peck wrote:> > Hullo. Welcome to my question. > > In my controller I need to get the number of items in a table. > > If I was just using MySQL, I''d do "select count(*) from blah where > blah > blah blah". > > What is the way to do this in my controller? I''d like to avoid > something like Blah.find(:all, :conditions => blah blah).size >Blah.count(:all, :conditions => ...) or if you had a named_scope for that set of conditions, Blah.some_scope.count Fred> Is there a way to do the equivalent of select count(*) in the > controller? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 11 Dec 2008, at 16:05, Joe Peck wrote: > >> something like Blah.find(:all, :conditions => blah blah).size >> > Blah.count(:all, :conditions => ...) > > or if you had a named_scope for that set of conditions, > Blah.some_scope.count > > FredBeautiful. Thanks Fred, you seem to answer a lot of questions on this board. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---