Skip to content

Instantly share code, notes, and snippets.

@jparbros
Created September 4, 2012 20:54
Show Gist options
  • Select an option

  • Save jparbros/3626333 to your computer and use it in GitHub Desktop.

Select an option

Save jparbros/3626333 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
attr_accessible :name, :qty
has_many :product_sales
end
class Sale < ActiveRecord::Base
belongs_to :salesman
has_many :product_sales
end
class SaleObserver < ActiveRecord::Observer
def after_save(sale)
sale.product.update_attribute(:qty,(sale.product.qty - sale.qty))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment