Last active
October 20, 2016 20:47
-
-
Save nicksieger/791cefab815c0f071448090b0820ca07 to your computer and use it in GitHub Desktop.
Troubleshoot ActiveRecord callbacks; require/load this at the top of config/application.rb
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
module CallbackTrace | |
def self.included(kls) | |
kls.send :alias_method_chain, :_compile_filter, :trace | |
end | |
def _compile_filter_with_trace(filter) | |
generated_code = _compile_filter_without_trace(filter) | |
return generated_code if filter.is_a?(Array) || @kind == :around || !(@klass.ancestors.include?(ActiveRecord::Base)) | |
"($stdout.print 'Callback: #{@kind} #{@klass.name}##{@raw_filter}'; $stdout.puts self.inspect; #{generated_code})" | |
end | |
ActiveSupport::Callbacks::Callback.send :include, self | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also troubleshoot all ActiveSupport callbacks if you exclude the
|| !(@klass.ancestors.include?(ActiveRecord::Base))
bit at the end of line 8. When I wrote this up I was only interested in AR callbacks.