X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=app%2Fcontrollers%2Fpurchase_controller.rb;fp=app%2Fcontrollers%2Fpurchase_controller.rb;h=4445c07b838352860e3cb499bebf4fe890954c22;hb=56db4e1da35c068e247eadbd32edd0a09eb61127;hp=15164985e7cef175e59001f43587afbe80059c0a;hpb=ebb2b4d40713d535c06970b2a17aace4458ecf25;p=cs356-p2-videostore.git diff --git a/app/controllers/purchase_controller.rb b/app/controllers/purchase_controller.rb index 1516498..4445c07 100644 --- a/app/controllers/purchase_controller.rb +++ b/app/controllers/purchase_controller.rb @@ -50,6 +50,20 @@ class PurchaseController < ApplicationController return end + if @rentable.checkedout? + flash[:error] = "This #{@rentable.type} is already checked out!" + redirect_to :action => :rent_begin + return + end + + # Check out the item + checkout = Coitem.new + checkout.customer = @customer + checkout.rentable = @rentable + checkout.out_date = Time.now.to_date + checkout.due_date = @rentable.due_date + checkout.save! + # Actually record the purchase purchase = RentablePurchase.new purchase.customer_id = session[:customer_id]