This topic needs a title

Hi!

How can i find the total no. of records in the table in a controller.

Regards,

Swanand

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