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