- render :action => 'return'
- end
-
- def return_validate
- rentable_id = params[:rentable_id]
- @rentable = Rentable.find_by_id(rentable_id)
-
- if @rentable.nil?
- flash[:error] = "Unable to find this rentable"
- redirect_to :action => :return
- return
- end
-
- @coitem = Coitem.find_by_rentable_id(rentable_id)
- if @coitem.nil?
- flash[:error] = "This item is not checked out!"
- redirect_to :action => :return
- return
- end
-
- # Check if the item is overdue
- if @coitem.overdue?
- @coitem.customer.debt += @coitem.late_fee
- @coitem.customer.save
+ if request.post?
+ rentable_id = params[:rentable_id]
+ @rentable = Rentable.find_by_id(rentable_id)
+
+ if @rentable.nil?
+ flash[:notice] = "Unable to find this rentable"
+ redirect_to :action => :return
+ return
+ end
+
+ @coitem = Coitem.find_by_rentable_id(rentable_id)
+ if @coitem.nil?
+ flash[:notice] = "This item is not checked out!"
+ redirect_to :action => :return
+ return
+ end
+
+ # Check if the item is overdue
+ if @coitem.overdue?
+ @coitem.customer.debt += @coitem.late_fee
+ @coitem.customer.save
+ end
+
+ # Delete the row
+ @coitem.destroy
+
+ flash[:notice] = "Successfully returned item"
+ redirect_to :action => :return, :method => :get
+ else
+ render :action => 'return'