Inspecting model callback chains

Updated . Posted . Visible to the public.

If you need to look at the list of methods that are called upon certain events (like before/after saving etc), do this:

Model._save_callbacks.select {|cb| cb.kind == :before}.map{ |c| c.instance_variable_get :@filter }

Rails 2

User.after_save_callback_chain

To look at the method names only, you could do something like that:

User.after_save_callback_chain.collect(&:method)
Arne Hartherz
Last edit
Dominik Schöler
Keywords
activerecord, callbacks
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2010-10-14 10:23)