簡體   English   中英

印象派寶石和Friendly_id

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM