Skip to content

Instantly share code, notes, and snippets.

@genewoo
Forked from scottwb/application_controller.rb
Last active August 26, 2015 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genewoo/fd20d7d57b4cf9b9b7e7 to your computer and use it in GitHub Desktop.
Save genewoo/fd20d7d57b4cf9b9b7e7 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