LoginSignup
7
6

More than 5 years have passed since last update.

before/after filterの設定状況を確認する

Posted at

debuggerなどで

puts _process_action_callbacks

Controllerの継承とかextend ActiveSupport::Concernとかやってて、
skip_before_filter使ったときに良くわからない事になったので調べたらあった。
例えば次のようなデバッグプリントを追加してfilterを調査する。

hoge_controller.rb
class HogeController < MyBaseController
  puts _process_action_callbacks.map(&:raw_filter).inspect
  skip_before_filter :set_hage
  puts _process_action_callbacks.map(&:raw_filter).inspect
  ...
#=> [:verify_authenticity_token, :set_hage]
#=> [:verify_authenticity_token]

callbackの内容

(rdb:1) pp _process_action_callbacks.first
#<ActiveSupport::Callbacks::Callback:0x007f99d99c6060
 @callback_id=14,
 @chain=
  [#<ActiveSupport::Callbacks::Callback:0x007f99d99c6060 ...>,
   #<ActiveSupport::Callbacks::Callback:0x007f99ded359d0
    @callback_id=8,
    @chain=[#<ActiveSupport::Callbacks::Callback:0x007f99ded359d0 ...>],
    @compiled_options="true",
    @filter=:set_hage,
    @kind=:before,
    @klass=ActionController::Base,
    @options={:if=>[], :unless=>[]},
    @per_key={:if=>[], :unless=>[]},
    @raw_filter=:set_hage>],
 @compiled_options="true",
 @filter=:verify_authenticity_token,
 @kind=:before,
 @klass=ApplicationController,
 @options={:prepend=>true, :if=>[], :unless=>[]},
 @per_key={:if=>[], :unless=>[]},
 @raw_filter=:verify_authenticity_token>

Modelの場合は調べてない

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6