before_filter難しい・・・
以下のようにbefore_filterを2つ別の場所に書いてみた
app/controllers/application.rb
class ApplicationController < ActionController::Base before_filter(:check1, :except => [:error]) private def check1 : redirect_to(:action => "error") end end
app/controllers/hoge_controller.rb
class HogeController < ApplicationController before_filer(:check2, :only => [:action1]) def action1 end def error end private def check2 : end end
上記のようなソースを書いてaction1を実行する。
するとまずApplicationControllerに書いてあるbefore_filterが実行される。
ここまではいい。
問題はその状態でcheck1のredirect_toでerrorに飛んだ場合。
どういうわけかHogeControllerに書いてあるbefore_filterのcheck2が呼ばれているようだ。
actionはerrorを実行しているのだからcheck2のbefore_filterは実行しないはずである(:onlyオプションを指定してあるから)
う〜ん、いったいどういうことなんだろう?
もうちょっと調べてみよう。