1d5dc09877f2672b818cae74fcf08a960cb62e46
[cs356-p2-videostore.git] / app / controllers / game_policy_controller.rb
1 class GamePolicyController < ApplicationController
2
3   # Make sure that the user has logged in before they can take any action
4   before_filter :authorize, :only => [:index, :list, :show]
5
6   # Make sure the user is a manager if they want to modify data
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     @game_policy_pages, @game_policies = paginate :game_policies, :per_page => 10
20   end
21
22   def show
23     @game_policy = GamePolicy.find(params[:id])
24   end
25
26   def new
27     @game_policy = GamePolicy.new
28   end
29
30   def create
31     @game_policy = GamePolicy.new(params[:game_policy])
32     if @game_policy.save
33       flash[:notice] = 'GamePolicy was successfully created.'
34       redirect_to :action => 'list'
35     else
36       render :action => 'new'
37     end
38   end
39
40   def edit
41     @game_policy = GamePolicy.find(params[:id])
42   end
43
44   def update
45     @game_policy = GamePolicy.find(params[:id])
46     if @game_policy.update_attributes(params[:game_policy])
47       flash[:notice] = 'GamePolicy was successfully updated.'
48       redirect_to :action => 'show', :id => @game_policy
49     else
50       render :action => 'edit'
51     end
52   end
53
54   def destroy
55     GamePolicy.find(params[:id]).destroy
56     redirect_to :action => 'list'
57   end
58 end