
[ホーム]
[最新エントリー]
[あすなろBLOG]
[あすなろNEXTBLOG]
[あすなろカウンセラーBLOG]
[インタビュー]
[スペシャルコンテンツ]
[テックスペース]
|
|
次へ |
日比 知子
2008年01月14日
ControllerやActionを指定して処理ができます
after_controller_action
before_controller_action
ex. def after_blog_save
=> BlogController#save終了後処理をする。
ぐぐってヒントを見つける。
[Rails][cache] Sweeper
http://d.hatena.ne.jp/meritdemerit/20070607/p2
なんとなくはわかるけど、やっぱりよくわからないのでソースを見ることにする。
ソースを見るためにRails Referenceで検索する(rakでもよさそう)。右上にファイルの場所があるので確認。
vendor/rails/actionpack/lib/action_controller/caching.rb
http://api.rubyonrails.org/classes/ActionController/Caching/Sweeping.html
ソースを読む:cache_sweeperキーワード
1 def cache_sweeper(*sweepers)
2 return unless perform_caching
3 configuration = sweepers.extract_options! 4 sweepers.each do |sweeper|
5 ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
6 sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance 7 if sweeper_instance.is_a?(Sweeper)
8 around_filter(sweeper_instance, :only => configuration[:only])
9 else 10 after_filter(sweeper_instance, :only => configuration[:only])
11 end 12 end 13 end
ソースを読む:after処理のエントリポイント
1 def after(controller)
2 callback(:after)
3 # Clean up, so that the controller can be collected after this request 4 self.controller = nil 5 end
ソースを読む:after_controller_action処理の呼び出し
1 def callback(timing)
2 controller_callback_method_name = "#{ timing}_#{controller.controller_name.underscore}" 3 action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}" 4 send!(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
5 send!(action_callback_method_name) if respond_to?(action_callback_method_name, true)
6 end
最後の、"send!(action...:自分にメソッドが定義されていたら送る"ってところが実際の呼び出し。
ふむむソース追うのが面倒だと思ってしまった私はRailsへの愛が足りないのかな・・・
それともまだ確定してないからドキュメントにないのかもしれませんね。
|
|
次へ |
|
|
[ホーム]
[ブログコンセプト]
[個人情報]
[著作権]
