Forum: Ruby on Rails Declaring ActiveRecord observers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
642a55efaf21673ee542bc17e64c8ed1?d=identicon&s=25 Juan Lupión (Guest)
on 2006-03-04 17:08
(Received via mailing list)
Hello

I'm using the 'act_as_authenticated' plugin to implement a small and
simple authentication system in my app.  Everything is working just
fine and the world is a better place to live in.  The plugin creates a
ActiveRecord observer in order to send the newly registered user a
confirmation e-mail.

Per the API docs [1], one should declare the observer in the
config/environment.rb file under the 'config.active_record.observers =
:comment_observer, :signup_observer'.

But reading the generated source code, the plugin author recommends
declaring the observer in my ApplicationController with a 'observer
:user_observer' clause.

The observer gets triggered in both cases, but I am curious about this,

So, what is the "Rails way" of activating observers?


1. http://rubyonrails.org/api/classes/ActiveRecord/Ob...

--
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-03-04 20:25
(Received via mailing list)
On 3/4/06, Juan Lupión <pantulis@gmail.com> wrote:
> :comment_observer, :signup_observer'.
> 1. http://rubyonrails.org/api/classes/ActiveRecord/Ob...
>

Using config.active_record.observers ensures the Observer is always
loaded.  It's actually probably a better way to go, because you don't
have to make sure to load it when in script/console.  (On the
flipside, it's always running.. so creating users from script/console
will send the emails out).

The only reason I don't use it is because it didn't seem to work
correctly in dev mode.  They would work the first request, but not
after because of the class reloading.  This may have been fixed
though.  Try it out and let me know if everything works fine.

--
Rick Olson
http://techno-weenie.net
642a55efaf21673ee542bc17e64c8ed1?d=identicon&s=25 Juan Lupión (Guest)
on 2006-03-05 14:27
(Received via mailing list)
> The only reason I don't use it is because it didn't seem to work
> correctly in dev mode.  They would work the first request, but not
> after because of the class reloading.  This may have been fixed
> though.  Try it out and let me know if everything works fine.

Uhm... declaring the observer only in "config.active_record_observers"
shows some erratic behaviour in development mode, as you said.  So my
previous statement "The observer gets triggered in both cases" was
plain wrong, I guess.

--
This topic is locked and can not be replied to.