1 class Coitem < ActiveRecord::Base
5 # Make sure the user typed in the ids
6 validates_presence_of :customer_id
7 validates_presence_of :rentable_id
9 # Make sure the user typed in numbers
10 validates_numericality_of :customer_id
11 validates_numericality_of :rentable_id
13 # Make sure this rentable was not already checked out
14 validates_uniqueness_of :rentable_id
16 # Make sure the associated rentable and customer are valid and exist
17 validates_associated :customer
18 validates_associated :rentable
21 return due_date < Time.now.to_date
25 days_late = Time.now.to_date - (due_date)
26 return VideoPolicy.find_by_day(8).fee * days_late.to_i
31 errors.add(:customer_id, "does not exist is the database") if customer.nil?
32 errors.add(:rentable_id, "does not exist in the database") if rentable.nil?