Observer is Deprecated

April 30th, 2007

So if you’ve seen deprecation warnings in your tests, you’ve probably been to http://www.rubyonrails.org/deprecation – for months, this page was just blank. I noticed today that it was updated, but it’s still pretty flimsy, sadly.

In one of my apps, I was using acts_as_authenticated from way back, and I’d been ignoring the error:

DEPRECATION WARNING: observer is deprecated and will be removed from Rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from /home/jason/dev/myapp/config/../app/controllers/account_controller.rb:2)

DEPRECATION WARNING: depend_on is deprecated and will be removed from Rails 2.0 See http://www.rubyonrails.org/deprecation for details. (called from observer_without_deprecation at /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/deprecated_dependencies.rb:29)

This particular deprecation is not yet mentioned on the deprecation page, but I managed to track it down. What’s deprecated is calling ‘observer’ from a controller. Instead, you need to set it in your config/environment.rb file:


        config.active_record.observers = :user_observer

That’s it.

Sorry, comments are closed for this article.