Emil Kampp
2014-Mar-11 21:15 UTC
Is it possible to put association callbacks in -extensions?
I have a case, where I would like a Log event to take place each time an association is added or removed. This is currently implemented like this: has_many :levels, after_add: :log_adding_event, after_remove: :log_removing_event def log_adding_event object Log.create(object, "adding") end def log_removing_event object Log.create(object, "removing") end The fact that the callbacks isn't aware of the association they'r triggered by. This means, that I need two separate methods to differentiate between adding and removing objects. I know that extending the association allows methods to know about all kinds of goodies about the proxy association, which brings me to my question: *Is it possible to move callbacks inside an association extension?* Cheers, Emil -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/33afb5f8-58e1-43ed-b942-3c17cb44e6ef%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.