I use the following fragment cache:
app/views/people/index.html.erb
<% cache do %>
<p>foobar</p>
<% end %>
That cache gets stored in views/localhost:3000/people/936e34304c10cd4b7469d805b7070ac4
I'd like to expire that cache with an after_update
callback in the Person
model but can't get it working.
app/models/person.rb
class Person < ActiveRecord::Base
after_update :sweep_cache
private
def sweep_cache
ActionController::Base.new.expire_fragment(controller: 'people',
action: 'index')
end
end
This code leads to this error:
Adding include Rails.application.routes.url_helpers
to the method doesn't help. What is the correct code for the sweep_cache
method to work?