Prettify the Game system
authorIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 06:55:05 +0000 (22:55 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 06:55:05 +0000 (22:55 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/game_controller.rb
app/views/game/index.rhtml [new file with mode: 0644]
app/views/game/list.rhtml
app/views/game/search.rhtml [moved from app/views/game/searchbyname.rhtml with 56% similarity]
app/views/game/searchresults.rhtml
app/views/layouts/admin.rhtml

index 31fe67e..c75ce07 100644 (file)
@@ -1,11 +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)
@@ -53,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
diff --git a/app/views/game/index.rhtml b/app/views/game/index.rhtml
new file mode 100644 (file)
index 0000000..280522d
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Game Maintenence</h1>
+
+<h3>Actions</h3>
+<ul>
+  <li><%= link_to 'List All Games', :action => 'list' %></li>
+  <li><%= link_to 'Search for a Game', :action => 'search' %></li>
+  <li><%= link_to 'Add a New Game', :action => 'new' %></li>
+</ul>
index d35c1eb..123e767 100644 (file)
@@ -1,26 +1,26 @@
-<h1>Listing games</h1>
+<h1>Listing Games</h1>
 
-<table>
+<table border="1">
   <tr>
     <th>Game ID</th>
     <th>Checked Out</th>
     <th>Title</th>
     <th>New Release</th>
     <th>Genre</th>
-    <td>Platform</th>
+    <th>Platform</th>
   </tr>
   
 <% for game in @games %>
   <tr>
     <td><%=h game.id %></td>
-    <td><%=h game.checkedout? %></td>
     <td><%=h game.title %></td>
-    <td><%=h game.newrelease %></td>
+    <td><%=h tf_to_yesno(game.checkedout?) %></td>
+    <td><%=h tf_to_yesno(game.newrelease) %></td>
     <td><%=h game.genre %></td>
     <td><%=h game.game_platform %></td>
-    <td><%= link_to 'Show', :action => 'show', :id => game %></td>
+    <td><%= link_to 'View', :action => 'show', :id => game %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => game %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :method => :post %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :method => :post %></td>
   </tr>
 <% end %>
 </table>
similarity index 56%
rename from app/views/game/searchbyname.rhtml
rename to app/views/game/search.rhtml
index a5a4f8b..b4beb0f 100644 (file)
@@ -1,7 +1,7 @@
 <h1>Search for a Game by Name</h1>
 
-<%= start_form_tag :action => 'searchresults'%>
-<%= text_field 'q', nil  %>
+<%= start_form_tag :action => 'search%>
+<%= text_field 'q', nil %>
   <%= submit_tag 'Search' %></form>
 <%= end_form_tag %>
 
index 54e7998..203f4cc 100644 (file)
@@ -1,27 +1,29 @@
-<h1>Search Results</h1>
+<h1>Search Results for '<%= @query[0].to_s %>'</h1>
 
 <% if @games.empty? %>
 <p>Sorry, there were no results</p>
 <% else %>
-<table>
+<table border="1">
   <tr>
-  <th>Game ID</th>
-  <th>Checked Out</th>
-  <% for column in Game.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
+    <th>Game ID</th>
+    <th>Checked Out</th>
+    <th>Title</th>
+    <th>New Release</th>
+    <th>Genre</th>
+    <td>Platform</th>
   </tr>
 
 <% for game in @games %>
   <tr>
-  <td><%=h game.id %></td>
-  <td><%=h game.checkedout? %></td>
-  <% for column in Game.content_columns %>
-    <td><%=h game.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => game %></td>
+    <td><%=h game.id %></td>
+    <td><%=h game.title %></td>
+    <td><%=h tf_to_yesno(game.checkedout?) %></td>
+    <td><%=h tf_to_yesno(game.newrelease) %></td>
+    <td><%=h game.genre %></td>
+    <td><%=h game.game_platform %></td>
+    <td><%= link_to 'View', :action => 'show', :id => game %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => game %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :post => true %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => game }, :confirm => 'Are you sure?', :method => :post %></td>
   </tr>
 <% end %>
 </table>
index bb59815..d271822 100644 (file)
@@ -17,7 +17,7 @@
       <p><%= link_to "Return Items", :controller => 'coitem', :action => 'return' %></p>
       <br/>
       <p><%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %></p>
-      <p><%= link_to "Game Maintenence", :controller => 'game', :action => 'list' %></p>
+      <p><%= link_to "Game Maintenence", :controller => 'game', :action => 'index' %></p>
       <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %></p>
       <p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %></p>
       <br/>