0

I'm trying to make a chart using Chartkick and am getting this error: undefined method 'group_by_day' for 10:Fixnum.

As recommended by this SO post, I installed the gem groupdate, so that isn't the problem.

My index method from my tasks_controller is:

def index
  @tasks = Task.where(user_id: current_user.id).order("created_at DESC")
end

And my erb in tasks#index is:

<%= line_chart @tasks.map { |task|
      {name: task.name, data: task.reps.group_by_day(:created_at)}
   } %>

Can anyone see where I'm going wrong here?

Community
  • 1
  • 1
Liz
  • 1,369
  • 2
  • 26
  • 61
  • Well `task.reps` is a number, not sure how one would group that by day. Probably you need something other than `task.reps`. – Andrew Marshall Aug 06 '16 at 21:03
  • @AndrewMarshall Each set of reps was `created_at` on a day, so I guess I was hoping it would group based on that. How would I do it without grouping at all? – Liz Aug 06 '16 at 21:07
  • You’re missing what I (and the error) are indicating (unless that error doesn’t occur in your given view code): the value that `task.reps` returns is a number, and numbers can (apparently) not be `grouped_by_day`. There is no “set of reps”, it seems. – Andrew Marshall Aug 06 '16 at 21:09
  • @AndrewMarshall, sorry if I'm being obtuse. So how would I get the chart to render without grouping at all, to simply have a datapoint per task, with `created_on` on the X axis and the integer for `reps` on the Y axis? – Liz Aug 06 '16 at 21:18

0 Answers0