Add a space between the period and 'Days'
[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   def title
10     if type == MerchandisePurchase
11       return merchandise.title
12     else
13       return rentable.title
14     end
15   end
16
17   protected
18   def validate
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?
22   end
23 end