# Observers in extensions

**URL:** <https://www.ruby-forum.com/t/observers-in-extensions/106038>\
**Category:** Radiant CMS\
**Created:** [June 5, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/observers-in-extensions/106038 "2007-06-05T21:19:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/observers-in-extensions/106038/1 "2007-06-05T21:19:54Z")

</div>

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.

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/observers-in-extensions/106038/2 "2007-06-05T22:36:12Z")

</div>

Andrew,

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  
try.

Sean

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/observers-in-extensions/106038/3 "2007-06-05T23:00:15Z")

</div>

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?

Thanks,  
Andrew
