2012-10-19 16 views
0

我有一個控制器,其中:Rails的緩存清掃失敗上創建

caches_action :show 
cache_sweeper :the_model_sweeper, :only => [:update, :destroy] 

和清掃:

observe TheModel 

def after_save(the_model) 
    expire_cache(the_model) 
end 

def after_destroy(the_model) 
    expire_cache(the_model) 
end 

def expire_cache(the_model) 
    expire_action :controller => '/the_model', :action => 'show' 
end 

和我得到:

ActionController::RoutingError (No route matches {:controller=>"/the_model", :action=>"show"}): 

我猜問題是因爲清道夫被稱爲after_save,當在一個新的記錄上將沒有東西可以銷燬,儘管我已經專門說了它只是爲了swee p更新或刪除。

(我明明改名爲模型,「模型」爲例目的)

+0

您是否還在真實代碼中使用控制器名稱中的/? – Novae

+0

是的,我不得不使用它,因爲ActiveAdmin的問題 - 否則它會嘗試清除「admin/the_model」http://stackoverflow.com/questions/10465964/sweepers-not-working-unless-manually-invoked-這是怎麼回事 –

+0

代碼對我來說似乎沒有問題,我自己也沒有嘗試過。但是你有沒有試過after_update而不是after_save來驗證你的懷疑? – Novae

回答

0

的問題是由於使用ActiveAdmin,而忘記(DOH ...)補充:只=> [:update,:destroy]到該模型的活動管理配置