Add GamePolicy and integrate with the Game model
[cs356-p2-videostore.git] / app / controllers / game_policy_controller.rb
diff --git a/app/controllers/game_policy_controller.rb b/app/controllers/game_policy_controller.rb
new file mode 100644 (file)
index 0000000..9ef608f
--- /dev/null
@@ -0,0 +1,51 @@
+class GamePolicyController < 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
+    @game_policy_pages, @game_policies = paginate :game_policies, :per_page => 10
+  end
+
+  def show
+    @game_policy = GamePolicy.find(params[:id])
+  end
+
+  def new
+    @game_policy = GamePolicy.new
+  end
+
+  def create
+    @game_policy = GamePolicy.new(params[:game_policy])
+    if @game_policy.save
+      flash[:notice] = 'GamePolicy was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @game_policy = GamePolicy.find(params[:id])
+  end
+
+  def update
+    @game_policy = GamePolicy.find(params[:id])
+    if @game_policy.update_attributes(params[:game_policy])
+      flash[:notice] = 'GamePolicy was successfully updated.'
+      redirect_to :action => 'show', :id => @game_policy
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    GamePolicy.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end