Created
August 18, 2010 12:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: this works in Rails 2.x and yes, the script should be added to config/initializers
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
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)