I\'m doing some statics calculation in my product. A user has performed a number of operations, let\'s say posted comments. I want to be able to show them how many comment
Use group_by
@user.comments.group_by(&:week) class User < ActiveRecord::Base def week some_attribute_like_date.strftime('%Y-%W') end end
This will give you a grouped list in the format of YYYY-WW