Fix LIKE clauses in searches to match anywhere in the field
[cs356-p2-videostore.git] / app / controllers / game_controller.rb
index 42a037e..626d51a 100644 (file)
@@ -1,7 +1,11 @@
 class GameController < ApplicationController
+  layout "admin"
+
+  # Make sure that the user has logged in before they can take any action
+  before_filter :authorize
+
   def index
-    list
-    render :action => 'list'
+    render :action => 'index'
   end
 
   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
@@ -49,12 +53,13 @@ class GameController < ApplicationController
     redirect_to :action => 'list'
   end
 
-  def searchbyname
-    render :action => 'searchbyname'
-  end
-
-  def searchresults
-    query = params[:q]
-    @games = Game.find(:all, :conditions => ["title like ?", query[0]+"%"])
+  def search
+    if request.post?
+      @query = params[:q]
+      @games = Game.find(:all, :conditions => ["title like ?", "%#{@query[0]}%"])
+      render :action => 'searchresults'
+    else
+      render :action => 'search'
+    end
   end
 end