2

Rails 3.0.19アプリケーションにフラグメント キャッシュを実装しdalli、キャッシュ ストアとして使用しようとしています。これが私のキャッシュフラグメントスクリプトです:

- @presentations.each do |p|
  - cache "presentation", p do
    = render_presentation_object p

render_presetnation_objectいくつかの条件に基づいて特定のパーシャルを実際にレンダリングします。また、コントローラーにスイーパーを追加しました。

cache_sweeper :presentation_sweeper, :only => [:create, :update, :destroy]
caches_action :update 

スイーパーのコードは次のとおりです。

class PresentationSweeper < ActionController::Caching::Sweeper
  observe Presentation

  def after_save(presentation)
    expire_cache(presentation)
  end

  def after_update(presentation)
    expire_cache(presentation)
  end

  def after_destroy(presentation)
    expire_cache(presentation)
  end

  def expire_cache(presentation)
    expire_fragment "presentation", presentation
  end
end

このコードを使用してコントローラーから何かを更新しようとすると@presentation.update_attributes(params[:presentation])、エラーが発生しましたActiveRecord::StatementInvalid (RuntimeError: can't modify frozen object:

私が見逃しているものはありますか?

4

2 に答える 2

7

gem rack-mini-profiler http://miniprofiler.com/が AR に実行時の変更を加えていたため、問題が発生していました。その宝石を削除すると問題が解決し、すべてがうまく機能するようになりました。

于 2013-01-17T10:55:44.037 に答える