undefined method `group_by_day' - rails 3.2

前端 未结 2 1199
半阙折子戏
半阙折子戏 2020-12-19 17:07

I want to make a line-chart of the number of User signups (per day) using chartkick, it is a simple one line code but it is giving an error



        
相关标签:
2条回答
  • 2020-12-19 17:45

    I can't see the definition of the group_by_day method. This is not a standard method. May be you are referencing group_by.

    In any case, group_by is not defined for the ActiveRecord class. It's defined on array.

    You first have to fetch the record into an Array. Also, if created_at is a method, you need to pass is using the &.

    User.all.group_by(&:created_at)
    

    Also, I'm not sure the .count at the end behaves as you may expect. It's counting the groups of the dates (and in case of created_at it will return almost one item for each record because the created_at is really hardly duplicated)

    0 讨论(0)
  • 2020-12-19 18:01

    To have group_by_day supported, you need to bundle another gem: groupdate from the same author of Chartkick.

    0 讨论(0)
提交回复
热议问题