42a037e0a5a1feb6773c6114cf2145d4b6a10f7d
[cs356-p2-videostore.git] / app / controllers / game_controller.rb
1 class GameController < ApplicationController
2   def index
3     list
4     render :action => 'list'
5   end
6
7   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
8   verify :method => :post, :only => [ :destroy, :create, :update ],
9          :redirect_to => { :action => :list }
10
11   def list
12     @game_pages, @games = paginate :games, :per_page => 10
13   end
14
15   def show
16     @game = Game.find(params[:id])
17   end
18
19   def new
20     @game = Game.new
21   end
22
23   def create
24     @game = Game.new(params[:game])
25     if @game.save
26       flash[:notice] = 'Game was successfully created.'
27       redirect_to :action => 'list'
28     else
29       render :action => 'new'
30     end
31   end
32
33   def edit
34     @game = Game.find(params[:id])
35   end
36
37   def update
38     @game = Game.find(params[:id])
39     if @game.update_attributes(params[:game])
40       flash[:notice] = 'Game was successfully updated.'
41       redirect_to :action => 'show', :id => @game
42     else
43       render :action => 'edit'
44     end
45   end
46
47   def destroy
48     Game.find(params[:id]).destroy
49     redirect_to :action => 'list'
50   end
51
52   def searchbyname
53     render :action => 'searchbyname'
54   end
55
56   def searchresults
57     query = params[:q]
58     @games = Game.find(:all, :conditions => ["title like ?", query[0]+"%"])
59   end
60 end