How to get model observer to work?


#1

I can’t seem to get a model observer to work. In my environment.rb I
have:

config.active_record.observers = :item_observer

In item_observer.rb I have:

class ItemObserver < ActiveRecord::Observer
observe Item

def after_update(item)
if @old.active != item.active
logger.debug ‘observer#after_update’
#…
end

@old = nil

end

def before_update(item)
logger.debug ‘observer#before_update’
@old = Item.find(item.id)
end
end

ItemObserver.instance # I’ve tried commenting this out too

Neither the before_update or after_update callbacks appear to be getting
called. How do I make this work?

Thanks,
Jack