Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get a list of all the filters on a given Rails 3 controller.
# Add these methods to your ApplicationController. Then, any controller
# that inherits from it will have these methods and can programmatically
# determine what filters it has set.
class ApplicationController < ActionController::Base
def self.filters(kind = nil)
all_filters = _process_action_callbacks
all_filters = all_filters.select{|f| f.kind == kind} if kind
all_filters.map(&:filter)
end
def self.before_filters
filters(:before)
end
def self.after_filters
filters(:after)
end
def self.around_filters
filters(:around)
end
end
@mhenrixon

This comment has been minimized.

Copy link

mhenrixon commented Apr 6, 2013

Unfortunately cancan adds some really messed up before_filters that are hard to match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.