Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Item < ActiveRecord::Base
- has_many :basket_items
- def withdraw(num)
- adjust_balance_and_save(-num)
- end
- def deposit(num)
- adjust_balance_and_save(num)
- end
- private
- def adjust_balance_and_save(num)
- self.quantity += num
- save!
- end
- def validate
- errors.add(:quantity, "is negative") if quantity < 0
- end
- end
Add Comment
Please, Sign In to add comment