Observers dont work

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.


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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs