Grouping by week/month/etc & ActiveRecord?

前端 未结 7 1307
野的像风
野的像风 2020-12-01 09:22

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

7条回答
  •  旧时难觅i
    2020-12-01 09:37

    In this case, the best solution for me was to either do it in straight SQL, or to use the Ruby group_by function:

    @user.all.group_by{ |u| u.created_at.beginning_of_month }
    

提交回复
热议问题