Is there any way to know all after_create call-back functions written in a particular model level?
For instance: I have written callback_function1
and callback_function2
in after_create
for the User model. I need to know both callback functions.
Sure. This wil give you all callbacks:
MODEL.__callbacks
You can then filter the result
MODEL.__callbacks[:create].select{_1.kind == :after}.map(&:filter)
If the callback is a symbol for a method, it will give you that symbol. It it’s a block, it will give you the file and line of the block.
@brenogazzola Fantastic. Thank you
In case the naming of that variable is unclear, that looks like undocumented internals. Just be a little careful using that in production. Those kinds of things can change without notice.