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