Hi!
How can i find the total no. of records in the table in a controller.
Regards,
Swanand
swanand deodhar wrote:
Hi!
How can i find the total no. of records in the table in a controller.
Regards,
Swanand
There is a count method on the model class.
A.
From the documentation at http://api.rubyonrails.org/ :
Person.find(:all)
returns an array of objects for all the rows fetched by SELECT * FROM
people
You can now use the size method to get the number of records in that
table
Person.count # returns the total count of all people
for conditional counts you can see docs
~cheers
Thnx for help. Tht worked
Bala P. wrote:
From the documentation at http://api.rubyonrails.org/ :
Person.find(:all)returns an array of objects for all the rows fetched by SELECT * FROM
people
You can now use the size method to get the number of records in that table
At the cost of copying all that data into Ruby objects.
Try Person.count or Person.count_by_sql.
–
Phlip
http://c2.com/cgi/wiki?ZeekLand ← NOT a blog!!