Skip to content

Instantly share code, notes, and snippets.

@aurelian
Created August 18, 2010 12:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aurelian/534568 to your computer and use it in GitHub Desktop.
Save aurelian/534568 to your computer and use it in GitHub Desktop.
shows what before_filter is executed and where's that filter defined. useful to debug before_filter madness
puts "\033[1;31m=> Loading hacks: #{__FILE__}\033[0m"
module BeforeFilterHacks
def self.included(base)
base.class_eval { alias_method_chain :call, :hacks }
end
def call_with_hacks(controller, &block)
message= if method.kind_of?(Proc)
method.to_s
else
"#{controller.method(method).owner}::#{method}"
end
if should_run_callback?(controller)
Rails.logger.info "++> \033[1;32m#{controller.request.request_uri} (#{controller.class.name})--> #{message}.\033[0m"
else
Rails.logger.info "--> \033[1;37m#{controller.request.request_uri} (#{controller.class.name})--> #{message}.\033[0m"
end
call_without_hacks(controller, &block)
end
end
ActionController::Filters::BeforeFilter.send(:include, BeforeFilterHacks)
@hisham
Copy link

hisham commented Sep 29, 2011

This script seems useful. Do you put it in config/initializers? I tried that but I get an exception when running the server:

config/initializers/before_filter_hacks.rb:25: uninitialized constant ActionController::Filters (NameError)

@aurelian
Copy link
Author

@hisham: this works in Rails 2.x and yes, the script should be added to config/initializers

@mikz
Copy link

mikz commented Mar 13, 2012

https://gist.github.com/af48839e7c9e1ac970c0 - for ActiveRecord callbacks also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment