[英]Fragment cache can't modify frozen object error rails 3
I am trying to implement fragment caching in a Rails 3.0.19
application and ussing dalli
as cache store. 我试图在
Rails 3.0.19
应用程序中实现片段缓存,并将dalli
作为缓存存储器。 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. render_presetnation_object
实际上根据某些条件渲染出特定的部分。 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:
当我尝试使用此代码
@presentation.update_attributes(params[:presentation])
从控制器更新任何东西时,它给出了一个错误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. 一个gem rack-mini-profiler http://miniprofiler.com/正在对AR进行运行时更改,这导致了问题。 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
通过在网站URL的末尾添加?pp = disable,将禁用miniprofiler,这可以让您测试是否是Miniprofiler引起了问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.