Undefined method 'cache_sweeper'
I am trying to set up some caching on my site and I am having trouble getting the cache utilizer running. I have followed Railscast , but when I try to load the model page I get an error. Here's what I've done so far:
1.) Added the app / sweepers directory and put the basic sweep in it:
class TeamMemberSweeper < ActionController::Caching::Sweeper
observe TeamMember
def after_create(team_member)
expire_nav_menus
end
def after_destroy(team_member)
expire_nav_menus
end
private
def expire_nav_menus(athlete_id)
expire_fragment(...)
end
end
2.) Add the following TeamMember model:
cache_sweeper :team_member_sweeper, :only => [:create, :destroy]
3.) Added the following line to config / environment.rb and restarted my server:
config.load_paths += %W( #{RAILS_ROOT}/app/sweepers )
At this point, when I access the TeamMember model, I get the following error:
undefined method `cache_sweeper' for #<Class:0x23128cc>
What am I missing to get this to work?
source to share
I think because
"cache_sweeper: team_member_sweeper ,: only => [: create ,: destroy]"
Should go into the controllers you want to expire for, not the model.
I'm having similar problems because I specifically WANT to expire from the model, but apparently this is not possible or very difficult to do in Rails.
source to share