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.
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.
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.