73049f3129fd3b841fb58d71818b3e46be25e4c5
[cs356-p2-videostore.git] / app / controllers / coitem_controller.rb
1 class CoitemController < ApplicationController
2   def index
3     list
4     render :action => 'list'
5   end
6
7   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
8   verify :method => :post, :only => [ :destroy, :create, :update ],
9          :redirect_to => { :action => :list }
10
11   def list
12     @coitem_pages, @coitems = paginate :coitems, :per_page => 10
13   end
14
15   def show
16     @coitem = Coitem.find(params[:id])
17   end
18
19   def new
20     @coitem = Coitem.new
21   end
22
23   def create
24     @coitem = Coitem.new(params[:coitem])
25     if @coitem.save
26       flash[:notice] = 'Coitem was successfully created.'
27       redirect_to :action => 'list'
28     else
29       render :action => 'new'
30     end
31   end
32
33   def edit
34     @coitem = Coitem.find(params[:id])
35   end
36
37   def update
38     @coitem = Coitem.find(params[:id])
39     if @coitem.update_attributes(params[:coitem])
40       flash[:notice] = 'Coitem was successfully updated.'
41       redirect_to :action => 'show', :id => @coitem
42     else
43       render :action => 'edit'
44     end
45   end
46
47   def destroy
48     Coitem.find(params[:id]).destroy
49     redirect_to :action => 'list'
50   end
51
52   # Awesome, paginating overdue list, ordered by customer
53   def overdue
54     @coitem_pages, @coitems = paginate :coitems, :per_page => 50, :conditions => "due_date < DATE('NOW', 'LOCALTIME')", :order => "customer_id"
55     render :action => 'list'
56   end
57 end