実装の仕方
class HogeController < ApplicationController
before_filter :foobar
private
def foobar
end
end
class HogeController < ApplicationController
before_filter do |controller|
end
end
class HogeFilter
def self.filter(controller)
end
end
class HogeController < ApplicationController
before_filter HogeFilter
end
- aroundフィルタオブジェクト(aroundの場合のみ)
class HogeFilter
def before(controller)
end
def after(controller)
end
end
class HogeController < ApplicationController
around_filter HogeController.new
end
フィルタチェーン
- before, after, around の3つのフィルタがある。
- フィルタチェーンを抜けるには、false を返す。(nilではダメ)
- フィルタチェーンを抜けると、あとのチェーンは実行されない。