Mon, 19 Aug 13

Listing controller filters in Rails 4

While trying to debug some filter/callback weirdness in a Rails 4 app[1], I tried to work out how to list all the callbacks for an action. I spent a while digging through the code until I found out that you could get the callbacks from the _process_action_callbacks method. So, popping something like this in your index action will write all the callbacks to the page. Magic.

def index
  render text: self._process_action_callbacks

[1] There's every chance that this same method works in earlier versions of Rails but I haven't tried it.