[英]Impressionist gem and Friendly_id
我有一个带有印象派和友好ID的Rails应用,我想在文章中显示页面浏览量。 问题是,印象派画家没有注册观看次数。
在印象派专家的错误跟踪器上,这是同样的问题。
我的文章模型:
class Article < ActiveRecord::Base
is_impressionable
extend FriendlyId
friendly_id :title, use: [:slugged, :history]
belongs_to :user
belongs_to :category
文章控制者:
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
我也重新启动了服务器,但是有同样的问题。
好的,可以解决。 只需在show controller中添加印象派(@model)
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
独特功能的小技巧:
def show
@article = Article.find(params[:id])
impressionist(@article, nil, { unique: [:session_hash] })
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.