Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gaga5lala/3b91004c2c6fca1f37daba162b277909 to your computer and use it in GitHub Desktop.
Save gaga5lala/3b91004c2c6fca1f37daba162b277909 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment