RailsのCacheSweeperは非常に便利なのですが、 callbackからコントローラのインスタンス変数にアクセスできると もっと便利になる気がします。

ソースコードを読んでみたら、やっぱりみんなそう思うようで、 assignsメソッドが用意されていました。

   1  class PostsSweeper < ActionController::Caching::Sweeper
   2    observe Post
   3  
   4    def after_posts_rating
   5      expire_fragment "posts/show/#{assigns(:post).id}"
   6    end
   7  end

こんな風に書けます。これは便利。

posted by Png genki on Tue 8 Jan 2008 at 07:48
Contents
Sweeperのcallbackからcontrollerのインスタンス変数にアクセスする方法
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ