Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created February 17, 2012 06:12
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save scottwb/1851142 to your computer and use it in GitHub Desktop.
Save scottwb/1851142 to your computer and use it in GitHub Desktop.
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
Copy link

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