Forum: Ruby on Rails Observers dont work

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
328f0bb678423fcea01ebe3b0edc74e6?d=identicon&s=25 Ben Johnson (benjohnson)
on 2007-05-04 23:37
I have this:

class UserObserver < ActiveRecord::Observer
  def before_save(user)
    raise "wtf"

I resarted my web server (mongrel) and everything. When I save a user
object I don't get an error at all, it works fine. Any ideas why this is
not working?

Thanks for your help.
58e87dd3aaaecd0d99a59985e3ca49f3?d=identicon&s=25 Lourens Naude (Guest)
on 2007-05-05 01:27
(Received via mailing list)

You need to register your observers.I use the following snippet in my
apps ( in environment or shared lib required on startup ) :

ActiveRecord::Base.observers = Dir.chdir( File.join( RAILS_ROOT,
'app', 'observers' ) ) {
*.rb").collect{|o| o.gsub!('.rb','').split('/').last.to_sym }

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