Ruby on rails 在更新后回调中终止\u片段

Ruby on rails 在更新后回调中终止\u片段,ruby-on-rails,caching,ruby-on-rails-4,Ruby On Rails,Caching,Ruby On Rails 4,我使用以下片段缓存: app/views/people/index.html.erb 此代码导致以下错误: 将include Rails.application.routes.url\u helpers添加到方法没有帮助。sweep\u cache方法的正确代码是什么?此问题没有答案。尽管如此,如果您仍然选择尝试在模型中使用仅限控制器的代码,您可以尝试将include Rails.application.routes.url\u helpers添加到类中,而不是添加到方法中。很可能会出现后续的错

我使用以下片段缓存:

app/views/people/index.html.erb

此代码导致以下错误:


将include Rails.application.routes.url\u helpers添加到方法没有帮助。sweep\u cache方法的正确代码是什么?

此问题没有答案。尽管如此,如果您仍然选择尝试在模型中使用仅限控制器的代码,您可以尝试将include Rails.application.routes.url\u helpers添加到类中,而不是添加到方法中。很可能会出现后续的错误,或者可能不会。只是好奇:你成功地做到了吗?很高兴知道。顺便说一句,屏幕播放得不错。
<% cache do %>
  <p>foobar</p>
<% end %>
class Person < ActiveRecord::Base
  after_update :sweep_cache

  private
  def sweep_cache
    ActionController::Base.new.expire_fragment(controller: 'people',
                                               action: 'index')
  end
end