On 17 Mar., 16:05, Nish Patel <[email protected]>
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to