saasbook

movie_sweeper.rb

Apr 4th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. class MovieSweeper < ActionController::Caching::Sweeper
  2.   observe Movie
  3.   # if a movie is created or deleted, movie list becomes invalid
  4.   def after_create(movie)  ; expire_action :action => 'index' ;  end
  5.   def after_destroy(movie) ; expire_action :action => 'index' ;  end
  6.   # if a movie is updated, its cached 'show' view becomes invalid
  7.   def after_update(movie) ; expire_fragment movie_path(movie) ; end
  8. end
  9.  
  10. # IMPORTANT: must add following to top of MoviesController:
  11. cache_sweeper :movie_sweeper
  12. caches_action :index, :show
Add Comment
Please, Sign In to add comment