Read my latest article: Ezra Zygmuntowicz -- Farewell, Friend. (posted Mon, 01 Dec 2014 17:53:00 GMT)

Where did my observer go?

Posted by Tue, 28 Feb 2006 05:05:00 GMT

4 comments Latest by Robby Russell Tue, 14 Mar 2006 15:05:29 GMT

I was playing around with an application from script/console and all of a sudden… my Observers just stopped working. It took me a while to figure out that when I would call Dispatcher.reset_application!... it wouldn’t reload config/environment.rb where I have defined the observers.

I really don’t like that this is the current implementation for invoking Observers and adding them to the controllers is not kosher with my (do-it-in-script-console) approach.

The current solution?


# app/models/foo_bar.rb
class FooBar < ActiveRecord::Base
end

FooBarObserver.instance

... there needs to be a better way!

Subscribe to my RSS feed Enjoying the content? Be sure to subscribe to my RSS feed.
comments powered by Disqus
Comments

Leave a response

  1. Avatar
    Michael Gorsuch Tue, 28 Feb 2006 12:21:13 GMT
    Robby – I thought that you invoked Observers in rails as follows:
    observer :foo_bar_observer
    
  2. Avatar
    Robby Russell Tue, 28 Feb 2006 14:19:37 GMT Recommend me on Working with Rails

    Michael,

    Do you mean in config/environment.rb?

    Yes, you do… but if you are in script/console and run Dispatcher.reset_application! it doesn’t reload your Observers.

  3. Avatar
    Michael Gorsuch Tue, 14 Mar 2006 12:05:00 GMT

    Sorry for the late response:

    I thought that was placed in the controller class.

    For example, FooController has a line at the top of the class stating:

      observer :foo_bar_observer
    
  4. Avatar
    Robby Russell Tue, 14 Mar 2006 15:05:29 GMT Recommend me on Working with Rails

    Michael,

    That assumes that your application is always engaged through your controllers. If you have a script that engages your models… do you not want your observers to still work?