【问题标题】:Rails cache sweeper fails on createRails 缓存清扫器在创建时失败
【发布时间】:2012-10-19 12:25:17
【问题描述】:

我有一个控制器,其中:

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,当在新记录上时不会有任何东西可以破坏,即使我已经明确表示它只是在更新或删除时清扫。

(出于示例目的,我显然已将模型重命名为“模型”)

【问题讨论】:

  • 你是不是也在你的真实代码中使用控制器名中的/?
  • 是的,由于 ActiveAdmin 的问题,我不得不使用它 - 否则它会尝试清除“admin/the_model”stackoverflow.com/questions/10465964/…
  • 代码对我来说似乎很好,无需亲自尝试。但是您是否尝试过 after_update 而不是 after_save 来验证您的怀疑?
  • 事实证明,您的最后一条评论引发了顿悟!我从 active_admin 模型配置中丢失了 ":only => [:update, :destroy]"。我会尽快发布答案

标签: ruby-on-rails ruby-on-rails-3 activeadmin sweeper


【解决方案1】:

问题是由于使用了 ActiveAdmin,而忘记了 (doh...) 将 :only => [:update, :destroy] 添加到该模型的活动管理配置中

【讨论】:

    猜你喜欢
    • 2011-04-15
    • 1970-01-01
    • 2012-08-07
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    相关资源
    最近更新 更多