Add Purchase system
[cs356-p2-videostore.git] / app / models / purchase.rb
1 class Purchase < ActiveRecord::Base
2   belongs_to :customer
3
4   validates_presence_of :customer_id
5   validates_presence_of :date
6   validates_presence_of :price
7   validates_numericality_of :price
8
9   protected
10   def validate
11     errors.add(:price, "cannot be negative") if price < 0
12     errors.add(:price, "cannot be less than $0.01") if price < 0.01
13     errors.add(:customer_id, "does not exist in the database") if customer.nil?
14   end
15 end