Where did my observer go?

Reading time: ~1 min ❓Shorter than a Rails console boot time

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!

Hi, I'm Robby.

Robby Russell

I run Planet Argon, where we help organizations keep their Ruby on Rails apps maintainable—so they don't have to start over. I created Oh My Zsh to make developers more efficient and host both the On Rails and Maintainable.fm podcasts to explore what it takes to build software that lasts.