Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Stefan Wintermeyer's Profile

GitHub User: wintermeyer

Site: http://www.wintermeyer.de

Comments by Stefan Wintermeyer

Avatar

I agree with your point of solving this in a model instead of a sweeper in the controller. It took me a couple of hours to solve this problem the IMO proper way.

Add the following to your model in a Rails 3.2 app (here the Class is Company):

ruby
after_create   :expire_cache
after_update   :expire_cache
before_destroy :expire_cache

def expire_cache
  ActionController::Base.expire_page(Rails.application.routes.url_helpers.company_path(self))
  ActionController::Base.expire_page(Rails.application.routes.url_helpers.companies_path)
end