Hi all, as you may have gathered I am a newbie to rails and programming. I want to count the number of enquiries in the database and produce it as a number in the view preferably in the index page. All I want is the number of items in the database and everytime ones added or deleted the number will go up or down. Something like this: Enquries Today: ''whatever the number of them are'' Thank you clever people!!!! Your help you been greatly appreciated -- 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 15:27 UTC
Re: How to create a simple loop counter
On 17 Mar., 16:05, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > as you may have gathered I am a newbie to rails and programming. I > want to count the number of enquiries in the database and produce it as > a number in the view preferably in the index page. All I want is the > number of items in the database and everytime ones added or deleted the > number will go up or down. > > Something like this: > > Enquries Today: ''whatever the number of them are'' > > Thank you clever people!!!!Assuming the name of your model is Item, you can do it this way: Enquries Today: <%= Item.count %> Just replace "Item" with whatever your model is called. #count is a method provided by ActiveRecord, that will return the number of records in the table that the table belongs to, "items" for example. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 15:28 UTC
Re: How to create a simple loop counter
On 17 Mar., 16:27, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote:> On 17 Mar., 16:05, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Hi all, > > > as you may have gathered I am a newbie to rails and programming. I > > want to count the number of enquiries in the database and produce it as > > a number in the view preferably in the index page. All I want is the > > number of items in the database and everytime ones added or deleted the > > number will go up or down. > > > Something like this: > > > Enquries Today: ''whatever the number of them are'' > > > Thank you clever people!!!! > > Assuming the name of your model is Item, you can do it this way: > > Enquries Today: <%= Item.count %> > > Just replace "Item" with whatever your model is called. #count is a > method provided by ActiveRecord, that will return the number of > records in the table that the table belongs to, "items" for example.* in the model that the table belongs to, "items" for example. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 15:29 UTC
Re: How to create a simple loop counter
On 17 Mar., 16:28, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote:> On 17 Mar., 16:27, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On 17 Mar., 16:05, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > Hi all, > > > > as you may have gathered I am a newbie to rails and programming. I > > > want to count the number of enquiries in the database and produce it as > > > a number in the view preferably in the index page. All I want is the > > > number of items in the database and everytime ones added or deleted the > > > number will go up or down. > > > > Something like this: > > > > Enquries Today: ''whatever the number of them are'' > > > > Thank you clever people!!!! > > > Assuming the name of your model is Item, you can do it this way: > > > Enquries Today: <%= Item.count %> > > > Just replace "Item" with whatever your model is called. #count is a > > method provided by ActiveRecord, that will return the number of > > records in the table that the table belongs to, "items" for example. > > * in the model that the table belongs to, "items" for example.Argh, in the table that model belongs to, of course. So sorry. :/ --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org wrote:> On 17 Mar., 16:28, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote: >> >> > > Thank you clever people!!!! >> >> > Assuming the name of your model is Item, you can do it this way: >> >> > Enquries Today: <%= Item.count %> >> >> > Just replace "Item" with whatever your model is called. #count is a >> > method provided by ActiveRecord, that will return the number of >> > records in the table that the table belongs to, "items" for example. >> >> * in the model that the table belongs to, "items" for example. > > Argh, in the table that model belongs to, of course. So sorry. :/Hi thankyou for that very quick reply but I getting: undefined method `count'' for #<Enquiry:0x41698fc> I am placing this in my index page like this: Enquries Today: <%= enquiry.count %> thanks again -- 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 -~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-17 15:41 UTC
Re: How to create a simple loop counter
On 17 Mar., 16:33, Nish Patel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org wrote: > > On 17 Mar., 16:28, "ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org" <ruby...-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org> wrote: > > >> > > Thank you clever people!!!! > > >> > Assuming the name of your model is Item, you can do it this way: > > >> > Enquries Today: <%= Item.count %> > > >> > Just replace "Item" with whatever your model is called. #count is a > >> > method provided by ActiveRecord, that will return the number of > >> > records in the table that the table belongs to, "items" for example. > > >> * in the model that the table belongs to, "items" for example. > > > Argh, in the table that model belongs to, of course. So sorry. :/ > > Hi thankyou for that very quick reply but I getting: > > undefined method `count'' for #<Enquiry:0x41698fc> > > I am placing this in my index page like this: > > Enquries Today: <%= enquiry.count %>Oh, that''s probably because "enquiry" is a local variable. You need to call the #count _class method_ on your model. So you''ll have to do it like this: Enquries Today: <%= Enquiry.count %> Notice, I use a capital E. The #count method is not available on instances of Enquiry (a specific record in your database), but as a class method of your model. "Enquiry" in your case. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for your help, that works fine now!! -- 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 -~----------~----~----~----~------~----~------~--~---