How to write a rails query that returns the count by Month?
activerecord, ruby-on-rails, ruby-on-rails-3
Solution
There are count and group statements available in active record so you could do something similar to
NewsFeed.count(:group=>"date_trunc('month', created_at)",:conditions=>"user_id NOT IN (?)",[exluded_ids])
Problem
take a standard NewsFeed model (id,user_id) How can I query for the # of records per month in the NewsFeed model, and then exclude a few user_id's? Results would yield: ``` Jan - 313 Feb - 3131 Mar - 44444 etc... ``` Is there a simple way to do this with rails or do you need to write a query for each month? Thanks