decoder
decoder

Reputation: 61

How to get the count of all records of a model in Rails console

I am new to Rails.

I have an ActiveRecord model called Post. I'd like to get count of all the records of the Post model. How can I accomplish this?

Thanks in advance for your help.

Upvotes: 4

Views: 10074

Answers (2)

webster
webster

Reputation: 4012

Try Post.all.count in your rails console if you are on Rails 4.

UPDATE:

Post.count is better as cristian mentioned

Upvotes: 9

Sander Garretsen
Sander Garretsen

Reputation: 1723

Post.count

is what you are looking for.

Upvotes: 15

Related Questions