I’ve been going through the rails source for a while now, and I don’t think there’s a better way of getting the list of all callbacks other than: ActiveRecord::Callbacks::CALLBACKS – which is a constant list.
Meaning if you’re using a gem like devise_invitable that adds a new callback called :invitation_accepted with the score :after and :before then ActiveRecord::Callbacks::CALLBACKS will not work.
Do you know of an easy fix, other than opening up rails modules and making sure there’s an internal list of call-backs per model class?
You can call
Model._save_callbacksto get a list of all callbacks on save.You can then filter it down to what kind you need e.g.
:beforeor:afterlike this:Works the same for
Model._destroy_callbacksetc.