6f7c8ee42c9a5c3f0546697b5ea1a12b0d08aac7
[cs356-p2-videostore.git] / app / controllers / customer_controller.rb
1 class CustomerController < 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     @customer_pages, @customers = paginate :customers, :per_page => 10
13   end
14
15   def show
16     @customer = Customer.find(params[:id])
17   end
18
19   def new
20     @customer = Customer.new
21   end
22
23   def create
24     @customer = Customer.new(params[:customer])
25     if @customer.save
26       flash[:notice] = 'Customer was successfully created.'
27       redirect_to :action => 'list'
28     else
29       render :action => 'new'
30     end
31   end
32
33   def edit
34     @customer = Customer.find(params[:id])
35   end
36
37   def update
38     @customer = Customer.find(params[:id])
39     if @customer.update_attributes(params[:customer])
40       flash[:notice] = 'Customer was successfully updated.'
41       redirect_to :action => 'show', :id => @customer
42     else
43       render :action => 'edit'
44     end
45   end
46
47   def destroy
48     Customer.find(params[:id]).destroy
49     redirect_to :action => 'list'
50   end
51 end