Created
September 4, 2012 20:54
-
-
Save jparbros/3626333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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