1 class CoitemController < ApplicationController
3 # Make sure that the user has logged in before they can take any
4 # action on checked out items
5 before_filter :authorize
9 render :action => 'list'
12 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
13 verify :method => :post, :only => [ :destroy, :create, :update ],
14 :redirect_to => { :action => :list }
17 @coitem_pages, @coitems = paginate :coitems, :per_page => 10
21 @coitem = Coitem.find(params[:id])
29 @coitem = Coitem.new(params[:coitem])
31 flash[:notice] = 'Coitem was successfully created.'
32 redirect_to :action => 'list'
34 render :action => 'new'
39 @coitem = Coitem.find(params[:id])
43 @coitem = Coitem.find(params[:id])
44 if @coitem.update_attributes(params[:coitem])
45 flash[:notice] = 'Coitem was successfully updated.'
46 redirect_to :action => 'show', :id => @coitem
48 render :action => 'edit'
53 Coitem.find(params[:id]).destroy
54 redirect_to :action => 'list'
57 # Awesome, paginating overdue list, ordered by customer
59 @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => "due_date < DATE('NOW', 'LOCALTIME')", :order => "customer_id"
60 render :action => 'list'
64 render :action => 'return'
68 rentable_id = params[:rentable_id]
69 @rentable = Rentable.find_by_id(rentable_id)
72 flash[:error] = "Unable to find this rentable"
73 redirect_to :action => :return
77 @coitem = Coitem.find_by_rentable_id(rentable_id)
79 flash[:error] = "This item is not checked out!"
80 redirect_to :action => :return
84 # Check if the item is overdue
86 @coitem.customer.debt += @coitem.late_fee
93 flash[:notice] = "Successfully returned item"
94 redirect_to :action => :return