문제

I am trying to implement fragment caching in a Rails 3.0.19 application and ussing dalli as cache store. Here is my cache fragment script:

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

render_presetnation_object actually render out specific partial based on some conditions. I also added a sweeper into my controller.

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

Here is the code for sweeper:

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

When I try to update any thing from controller using this code @presentation.update_attributes(params[:presentation]) , it gave an error ActiveRecord::StatementInvalid (RuntimeError: can't modify frozen object:

Is there any thing I am missing out?

도움이 되었습니까?

해결책

A gem rack-mini-profiler http://miniprofiler.com/ was doing some run-time changes to AR which was causing the issue. Removing that gem solved the issue and every thing works great now.

다른 팁

Further to Nazar Hussain's answer. By adding ?pp=disable to the end of your website URL this will disable the miniprofiler which may allow you to test wether it is Miniprofiler causing the issue

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top