2013-01-15 40 views
2

我試圖在Rails 3.0.19應用程序中執行片段緩存,並使用dalli作爲緩存存儲。這裏是我的緩存片段腳本:片段緩存無法修改凍結的對象錯誤軌道3

- @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:

有沒有我的任何東西錯過了?

+0

和其餘的錯誤? – sevenseacat

+0

'ActiveRecord :: StatementInvalid(RuntimeError:無法修改凍結對象:INSERT INTO'user_logins'('email','sign_in_at')VALUES('[email protected]','2013-01-15 19:50: 55')): –

+0

與演示文稿有什麼關係? – sevenseacat

回答

6

一顆寶石機架迷你配置文件http://miniprofiler.com/正在做一些運行時更改爲導致此問題的AR。去除那顆寶石解決了這個問題,現在每件事情都很好。

+2

已經創建了一個問題,所以看看鏈接更多更新https://github.com/SamSaffron/MiniProfiler/issues/106 –

0

除了納扎爾·侯賽因的回答。通過添加?pp =禁用到您的網站URL的末尾,這將禁用miniprofiler,它可能允許您測試它是Miniprofiler導致問題