Forum: Ruby on Rails newbe: observer setup

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.
David W. (Guest)
on 2006-02-20 01:57
(Received via mailing list)
Hi All,

Having problem setting up an observer to log changes to
a database.  I have following the Prag Rails book but think
I have something missing.  I am trying a simple puts to see
if the observer is working, but getting nothing on the console.

Here is what I have.  I don't get any errors.
Thanks for any suggestions/references to debugging.

Dave

The two models:

display_ad.rd

require 'observer'
class DisplayAd < ActiveRecord::Base
   include Observable
   has_many :activities
    #def after_update
     # puts "*************Updated display ad*************"
    #end
end

display_ad_observer.rd

class DisplayAdObserver < ActiveRecord::Observer
   observe DisplayAd

   def after_save(display_ad)
    an_display_ad.logger.info( "Added display ad: #{an_display_ad.id}")
    puts "*************Saved display ad*************"
   end

   def after_update(display_ad)
    puts "*************Updated display ad*************"
    an_display_ad.logger.info( "Updated display ad: #
{an_display_ad.id}")
   end
end
DisplayAdObserver.instance

And in environment.rb

  config.active_record.observers = :display_ad_observer
This topic is locked and can not be replied to.