I saw this Count records created within the last 7 days but still need some help in getting the syntax of COUNT right, right now I have
@count_users = User.count('comment')
which gives me Count of all comments but I need to know count of all comments made only in last 7 days or in last 1 month, but I am not able to figure out the correct syntax for it
This count:
Generates the following SQL:
So unless you have a comment column in your users table, it is not counting the right objects.
If you have a Comment model, you can use the following to count all comments created in the past 7 days:
If you want to count the Comments of a specific User, you can use this (assuming a Comment belongs_to a User and a User has_many Comments):