Skip to content

Instantly share code, notes, and snippets.

@eqdw
Created November 8, 2010 20:49
Show Gist options
  • Save eqdw/668231 to your computer and use it in GitHub Desktop.
Save eqdw/668231 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
scope :date_counts, lambda {
group('DATE_FORMAT(created_at, "%Y/%m")').count
}
##Post.date_counts GENERATES ERROR: ArgumentError: Unknown key(s): 2009/01, 2009/02, 2009/03, 2009/04, 2009/06 ... etc
def self.date_counts
self.group('DATE_FORMAT(created_at, "%Y/%m")').count
end
##Post.date_counts works as expected
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment