0

I have a controller where:

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

and sweeper:

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

and am getting:

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

The problem I'm guessing is becuase the sweeper is called after_save, when on a new record there will be nothing to destroy, even though I have specifically said for it only to sweep on update or delete.

(I have obviously renamed the model to "The Model" for example purposes)

Chris Edwards
  • 3,514
  • 2
  • 33
  • 40
  • Are you also using the / in the controller name in your real code? – Novae Oct 19 '12 at 12:27
  • Yes, I'm having to use that because of problems with ActiveAdmin - otherwise it tries to clear "admin/the_model" http://stackoverflow.com/questions/10465964/sweepers-not-working-unless-manually-invoked-what-is-going-on – Chris Edwards Oct 19 '12 at 12:29
  • Code seems fine to me without trying it out myself. But have you tried after_update instead of after_save to (in)validate your suspicion? – Novae Oct 19 '12 at 12:39
  • As it turns out your last comment triggered an epiphany! I was missing ":only => [:update, :destroy]" from the active_admin model config. I'll post the answer asap – Chris Edwards Oct 19 '12 at 12:42

1 Answers1

0

The problem was due to using ActiveAdmin, and forgetting (doh...) to add :only => [:update, :destroy] to the active admin config for that model

Chris Edwards
  • 3,514
  • 2
  • 33
  • 40