Observers in extensions

Is there a good way to add an ActiveRecord observer through and
extension’s activate method? I’m guessing the standard way (adding it
to the config in environment.rb) won’t work since the extension hasn’t
loaded yet.



You might be able to just ‘mention’ the class in the activate method so
it gets loaded. Then your observer would have to have an “observe” call
in its class. Not sure if that will actually work, but it’s worth a


Hi Sean,

It, looks like calling the (observer).instance method in activate does
the trick. I’m also mentioning it at the end of the two classes I’m
observing, so that could be doing it as well – haven’t tried figuring
out which is responsible yet.

I think my problem is actually related to the fact that the observer
doesn’t seem to get notified when the join table in a HABTM
relationship gets changed – only when one of the two actual models
does. I haven’t completely confirmed that yet, but that’s what it’s
looking like. That’s a more general Rails question I guess, but
anyone ever tackled that before?