Prettify the Purchase system
[cs356-p2-videostore.git] / app / controllers / rentable_policy_controller.rb
1 class RentablePolicyController < ApplicationController
2
3   # Make sure that a user logs in before doing any action here
4   before_filter :authorize, :only => [:index, :list, :show]
5
6   # Make sure the user is a manager before doing any action specified
7   before_filter :manager, :only => [:new, :create, :edit, :update, :destroy]
8
9   def index
10     list
11     render :action => 'list'
12   end
13
14   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15   verify :method => :post, :only => [ :destroy, :create, :update ],
16          :redirect_to => { :action => :list }
17
18   def list
19     @rentable_policy_pages, @rentable_policies = paginate :rentable_policies, :per_page => 10
20   end
21
22   def show
23     @rentable_policy = RentablePolicy.find(params[:id])
24   end
25
26   def new
27     @rentable_policy = RentablePolicy.new
28   end
29
30   def create
31     @rentable_policy = RentablePolicy.new(params[:rentable_policy])
32     if @rentable_policy.save
33       flash[:notice] = 'RentablePolicy was successfully created.'
34       redirect_to :action => 'list'
35     else
36       render :action => 'new'
37     end
38   end
39
40   def edit
41     @rentable_policy = RentablePolicy.find(params[:id])
42   end
43
44   def update
45     @rentable_policy = RentablePolicy.find(params[:id])
46     if @rentable_policy.update_attributes(params[:rentable_policy])
47       flash[:notice] = 'RentablePolicy was successfully updated.'
48       redirect_to :action => 'show', :id => @rentable_policy
49     else
50       render :action => 'edit'
51     end
52   end
53
54   def destroy
55     RentablePolicy.find(params[:id]).destroy
56     redirect_to :action => 'list'
57   end
58 end