I have a Rails app with impressionist and friendly id, I want to show page views in my articles. The problem is that impressionist is not registering the number of views.
It's the same problem here on impressionist's bug tracker .
My articles model:
class Article < ActiveRecord::Base
is_impressionable
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
belongs_to :user
belongs_to :category
Articles controller:
def show
@article = Article.find(params[:id])
if request.path != article_path(@article)
redirect_to @article, status: :moved_permanently
end
respond_to do |format|
format.html
format.json { render json: @article }
end
end
I also restarted the server, but having the same issue.
Ok there is a work around. Just add impressionist(@model) in the show controller
def show
@article = Article.find(params[:id])
impressionist(@article)
if request.path != article_path(@article)
redirect_to @article, status: :moved_permanently
end
respond_to do |format|
format.html
format.json { render json: @article }
end
end
Little tip for unique functionality:
def show
@article = Article.find(params[:id])
impressionist(@article, nil, { unique: [:session_hash] })
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.