I load my observers from the application.rb file like this;
config.active_record.observers = :admin_observer,
‘Message::MailObserver’, ‘Message::EventObserver’
That’s correct. This syntax hasn’t changed.
When I change my development setting to;
config.cache_classes = true
the observers get loaded and executed.
This would indicate that, normally in development mode, observer classes don’t get instantiated at all. This is strange, and I can’t reproduce this failure. I’ve just checked activerecord Railtie and the hooks to instantiate observers; it seems like everything is in place. Observer classes should always be instantiated once when ActiveRecord::Base is loaded and before every server request in development mode.
Try to provide us with more info. First, reset cache_classes setting to false (development mode default). Next, use the rails console to check up on the following:
ActiveRecord::Base.observers — it should match what you specified in config.active_record.observers
MyModel.count_observers — replace “MyModel” with the name of the model having observers. It will return the number of observers tied to this model; otherwise it will fail with a NoMethodError because the array hasn’t been initialized (this is a minor bug that I’m patching right now)
That's ok (I removed the AdminObserver from the previous example since
it was only a test)
Message::Mail.count_observers
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.size
That gives the error you describe.
Hope this helps. Strange that you don't have this behaviour in your
app though...