Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
return
end
+ # Check Rentable Policies
+ @maxvideos = RentablePolicy.find_by_name("MaxVideos")
+ if @rentable.class == Video and @customer.checked_out_videos >= @maxvideos.value
+ flash[:error] = "#{@maxvideos.description} LIMIT REACHED"
+ redirect_to :action => :rent_begin
+ return
+ end
+
+ @maxgames = RentablePolicy.find_by_name("MaxGames")
+ if @rentable.class == Game and @customer.checked_out_games >= @maxgames.value
+ flash[:error] = "#{@maxgames.description} LIMIT REACHED"
+ redirect_to :action => :rent_begin
+ return
+ end
+
# Check out the item
checkout = Coitem.new
checkout.customer = @customer
validates_presence_of :name, :email, :phone, :address
validates_numericality_of :debt
+ def checked_out_videos
+ coitems = Coitem.find_all_by_customer_id(id)
+ video_count = 0
+
+ for item in coitems
+ if item.rentable.class == Video
+ video_count += 1
+ end
+ end
+
+ return video_count
+ end
+
+ def checked_out_games
+ coitems = Coitem.find_all_by_customer_id(id)
+ game_count = 0
+
+ for item in coitems
+ if item.rentable.class == Game
+ game_count += 1
+ end
+ end
+
+ return game_count
+ end
+
protected
def validate