Forum: Ruby on Rails How to get model observer to work?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
37641533d39c169de08d16c246b0f56a?d=identicon&s=25 Jack Davis (Guest)
on 2006-02-22 22:28
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
This topic is locked and can not be replied to.