charlotte-ruby / impressionist

Rails Plugin that tracks impressions and page views
MIT License
1.54k stars 311 forks source link

Having an issue with connecting to Chartkick #252

Open RailsCod3rFuture opened 7 years ago

RailsCod3rFuture commented 7 years ago

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 methodthis_month' for #"` <%= 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]