3

印象派でフレンドリーな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

サーバーも再起動しましたが、同じ問題が発生しました。

4

2 に答える 2

9

回避策があります。ショーコントローラーに印象派(@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
于 2012-05-25T16:23:11.157 に答える
1

独自の機能に関するヒント:

def show
  @article = Article.find(params[:id])
  impressionist(@article, nil, { unique: [:session_hash] })
end
于 2014-03-20T18:29:00.953 に答える