ActiveRecord Callbacks List

You can call Model._save_callbacks to get a list of all callbacks on save. You can then filter it down to what kind you need e.g. :before or :after like this:

Model._save_callbacks.select {|cb| cb.kind == :before}

Works the same for Model._destroy_callbacks etc.


If you're working in a Rails version prior to the ._save_callbacks method, you can use the following:

# list of callback_chain methods that return a CallbackChain
Model.methods.select { |m| m.to_s.include? "callback" }.sort

# get all methods in specific call back chain, like after_save
Model.after_save_callback_chain.collect(&:method)

Note that if you simply want to trigger callbacks, you can use the #run_callbacks(kind) method:

o = Order.find 123 # Created with SQL
o.run_callbacks(:create)
o.run_callbacks(:save)
o.run_callbacks(:commit)

The docs say "There are nineteen callbacks in total"... but they don't seem to say what all of those 19 actually are!

For those who Googled "list of all ActiveRecord callbacks" like I did, here's the list (found by using ActiveRecord::Callbacks::CALLBACKS as described in the question):

:after_initialize
:after_find
:after_touch
:before_validation
:after_validation
:before_save
:around_save
:after_save
:before_create
:around_create
:after_create
:before_update
:around_update
:after_update
:before_destroy
:around_destroy
:after_destroy
:after_commit
:after_rollback