Reputation: 155
I am trying to use groupdate to count messages from a specific user for the last 30 days.
This seams to count all the messages instead of the 30 days. Can someone see what I'm doing wrong?
@individual_messages = Message.where("user_id = ?",current_user.id)
@chart_indiv_mess = @individual_messages.group_by_day(:created_at, range: 4.week.ago.midnight..Time.now, format: "%a, %b %e").count
I'm displaying the value then turning around and using chartkick to display the messages.
Upvotes: 0
Views: 83
Reputation: 6253
you can do this way to show data for chartkick
@data_for_chart = current_user.messages.group_by_month(:created_at, format: "%b %Y").count.map { |k,v| [k, v]}
inside your view that showing chart (chartkick) you can do like this below
<%= column_chart @data_for_chart %>
Upvotes: 1