I'm creating an activity chart, showing the number of records saved to a user's profile over time (in this case its 'user.notes' i.e. user has_many notes). The json output from the function below feeds nicely into a chart library.
The function below however does not output data for weeks without any activity...I need these 'holes', with correct week dates to be in there... can anyone suggest how I might be able to do this?
I believe the 'has_activity' gem has this functionality, however I would prefer to avoid using a whole gem to do this.
class Case < ActiveRecord::Base
def self.user_activity_profile(user)
array = []
user.notes.group_by{ |u| u.created_at.beginning_of_week }.each do |week, entries|
array << { week: week.strftime("%d %b"), count: entries.count }
end
array.to_json
end
end