Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counting page views using “impressionist” gem Ruby on Rails

I am using impressionist gem to count each page impression from people who seen article page but the problem is that i get it only work for one article and the counter for the other are for 0

this is my code

class Article < ActiveRecord::Base
  is_impressionable
end

class ArticlesController < ApplicationController
  impressionist actions: [:show], unique: [:session_hash]
end

This is my show action

<%= "#{@article.impressionist_count} views" %>
like image 295
Loenvpy Avatar asked Feb 13 '23 04:02

Loenvpy


1 Answers

Add this code in your controller ..

def show
   @article = Article.find
   impressionist(@article)
end
like image 191
sp1rs Avatar answered Apr 08 '23 18:04

sp1rs