Jonathan B. Abatayo

My personal blog.

Saturday, January 27, 2007

Ruby on Rails (notes for observers)

OBSERVERS

lib/inventory_init.rb
ActiveRecord::Base.observers = [:item_observer,
:item_supplier_observer]


config/environment.rb
require 'inventory.init'
config. load_path += %W(#RAILS_ROOT/app/observers)


class ItemObserver < ActiveRecord::Observer
def before_create(record)
#code here
end
def after_create(record)
#code here
end
end

def before_update(record)
@status = record.status
end

def after_update(record)
if @status == record.status
# Your code here.
end
end

2 Comments:

  • At 4:41 AM, Blogger Unknown said…

    This comment has been removed by a blog administrator.

     
  • At 11:30 AM, Anonymous Anonymous said…

    hello... hapi blogging... have a nice day! just visiting here....

     

Post a Comment

<< Home