1 class Purchase < ActiveRecord::Base
4 validates_presence_of :customer_id
5 validates_presence_of :date
6 validates_presence_of :price
7 validates_numericality_of :price
10 if type == MerchandisePurchase
11 return merchandise.title
19 errors.add(:price, "cannot be negative") if price < 0
20 errors.add(:price, "cannot be less than $0.01") if price < 0.01
21 errors.add(:customer_id, "does not exist in the database") if customer.nil?