Add VideoPolicy to the purchase path
[cs356-p2-videostore.git] / app / controllers / video_policy_controller.rb
diff --git a/app/controllers/video_policy_controller.rb b/app/controllers/video_policy_controller.rb
new file mode 100644 (file)
index 0000000..4be73da
--- /dev/null
@@ -0,0 +1,51 @@
+class VideoPolicyController < ApplicationController
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @video_policy_pages, @video_policies = paginate :video_policies, :per_page => 10
+  end
+
+  def show
+    @video_policy = VideoPolicy.find(params[:id])
+  end
+
+  def new
+    @video_policy = VideoPolicy.new
+  end
+
+  def create
+    @video_policy = VideoPolicy.new(params[:video_policy])
+    if @video_policy.save
+      flash[:notice] = 'VideoPolicy was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @video_policy = VideoPolicy.find(params[:id])
+  end
+
+  def update
+    @video_policy = VideoPolicy.find(params[:id])
+    if @video_policy.update_attributes(params[:video_policy])
+      flash[:notice] = 'VideoPolicy was successfully updated.'
+      redirect_to :action => 'show', :id => @video_policy
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    VideoPolicy.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end