Skip to content

Instantly share code, notes, and snippets.

@nicksieger
Last active October 20, 2016 20:47
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 nicksieger/791cefab815c0f071448090b0820ca07 to your computer and use it in GitHub Desktop.
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
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
@nicksieger
Copy link
Author

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.

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