Having an issue with connecting to Chartkick
Opened this issue · 0 comments
RailsCod3rFuture commented
What I'm trying to do is log the impression count for the User model show page, and output the information to a chart. What I have below is not working correctly. I'm getting ``"undefined method this_month' for #<Class:0x50931a8>"
` <%= line_chart current_user.impressionist_count %>` displays the graph, but it doesn't scope to days, weeks, months or years like I need to it. I'm using PostgresSQL, btw.
<div class="user-impressions-graph">
<%= line_chart @user_monthly_profile_views %>
</div>
@user_monthly_profile_views = Impression.this_month.where(impresionable_id: current_user.id)
impression.rb
class Impression
#Impression Queries
scope :today, -> {where("created_at >= ? AND created_at < ?", Time.now.beginning_of_day, Time.now.end_of_day)}
scope :yesterday, -> {where("created_at >= ? AND created_at < ?", 1.day.ago.beginning_of_day, 1.day.ago.end_of_day)}
scope :this_month, -> {where("created_at >= ? AND created_at < ?", Time.now.beginning_of_month, Time.now.end_of_month)}
end
user.rb
is_impressionable :counter_cache => true
users_controller.rb
impressionist :actions => [:show]