charlotte-ruby / impressionist

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

Impressionist most_viewed items not working #268

Closed ghost closed 4 years ago

ghost commented 6 years ago

I've been unable to retrieve most viewed posts in my app with impressionist gem. Everything works fine with normal page views. I've tried this on another app and it works well. The only difference between the two apps is that the one that that worked uses SQLITE while the other PG.

I've implemented it by installing the gem and running the migration

rails g migration add_impressions_count_to_posts impressions_count:integer

Added this to Post.rb

is_impressionable :counter_cache => true

and

Post.order('impressions_count DESC')

Added this to posts_controller.rb in show action

@most_viewed = Post.order('impressions_count DESC').take(20)

And in my show page i have

<h4>20 Most Viewed in this Directory.</h4>
  <ol>
    <% @most_viewed.each do |post| %>
      <li><%= link_to post.title, post_path(post.id) %> (<%= post.impressionist_count %> Views) </li>
    <% end %>
  </ol>
claeusdev commented 5 years ago

I have just reproduced this same issue but it works in PG. Still, haven't figured a way out?