Small Cleanups + Merchandise Search master turned-in
authorIra W. Snyder <devel@irasnyder.com>
Tue, 27 Nov 2007 09:02:31 +0000 (01:02 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Tue, 27 Nov 2007 09:02:31 +0000 (01:02 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/merchandise_controller.rb
app/views/customer/searchresults.rhtml
app/views/game_policy/list.rhtml
app/views/merchandise/index.rhtml
app/views/merchandise/search.rhtml [new file with mode: 0644]
app/views/merchandise/searchresults.rhtml [new file with mode: 0644]
app/views/rentable_policy/list.rhtml
app/views/video_policy/list.rhtml
db/development.sqlite3

index 79a85dd..f819b30 100644 (file)
@@ -52,4 +52,14 @@ class MerchandiseController < ApplicationController
     Merchandise.find(params[:id]).destroy
     redirect_to :action => 'list'
   end
+
+  def search
+    if request.post?
+      @query = params[:q]
+      @merchandises = Merchandise.find(:all, :conditions => ["title like ?", "%#{@query[0]}%"])
+      render :action => 'searchresults'
+    else
+      render :action => 'search'
+    end
+  end
 end
index cc32efe..37d8b2e 100644 (file)
@@ -5,21 +5,21 @@
 <% else %>
 <table border="1">
   <tr>
-  <th>Customer ID</th>
-  <% for column in Customer.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
+    <th>Customer ID</th>
+    <th>Name</th>
+    <th>Phone</th>
+    <th>Balance</th>
   </tr>
 
 <% for customer in @customers %>
   <tr>
-  <td><%=h customer.id %></td>
-  <% for column in Customer.content_columns %>
-    <td><%=h customer.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => customer %></td>
+    <td><%=h customer.id %></td>
+    <td><%=link_to customer.name.to_s, :action => 'show', :id => customer %></td>
+    <td><%=h customer.phone %></td>
+    <td><%=h number_to_currency(customer.debt) %></td>
+    <td><%= link_to "Checked Out Items", :controller => :coitem, :action => 'filterbycustomerid', :id => customer %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => customer %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :post => true %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %></td>
   </tr>
 <% end %>
 </table>
index 327c35d..fdcaa05 100644 (file)
@@ -12,7 +12,6 @@
     <td><%=h game_policy.description %></td>
     <td><%=h number_to_currency(game_policy.fee) %></td>
     <td><%=h game_policy.period %> Days</td>
-    <td><%= link_to 'View', :action => 'show', :id => game_policy %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => game_policy %></td>
   </tr>
 <% end %>
index 6950e28..1abaee6 100644 (file)
@@ -3,5 +3,6 @@
 <h3>Actions</h3>
 <ul>
   <li><%= link_to 'List All Merchandise', :action => 'list' %></li>
+  <li><%= link_to 'Search for a Merchandise', :action => 'search' %></li>
   <li><%= link_to 'Add a New Merchandise Item', :action => 'new' %></li>
 </ul>
diff --git a/app/views/merchandise/search.rhtml b/app/views/merchandise/search.rhtml
new file mode 100644 (file)
index 0000000..142d401
--- /dev/null
@@ -0,0 +1,8 @@
+<h1>Search for a Merchandise by Name</h1>
+
+<%= start_form_tag :action => 'search' %>
+<%= text_field 'q', nil %>
+  <%= submit_tag 'Search' %></form>
+<%= end_form_tag %>
+
+<br />
diff --git a/app/views/merchandise/searchresults.rhtml b/app/views/merchandise/searchresults.rhtml
new file mode 100644 (file)
index 0000000..4a0fb5c
--- /dev/null
@@ -0,0 +1,25 @@
+<h1>Search Results for '<%= @query[0].to_s %>'</h1>
+
+<% if @merchandises.empty? %>
+<p>Sorry, there were no results</p>
+<% else %>
+<table border="1">
+  <tr>
+    <th>Merchandise ID</th>
+    <th>Title</th>
+    <th>Quantity Remaining</th>
+    <th>Price Per Unit</th>
+  </tr>
+
+<% for merchandise in @merchandises %>
+  <tr>
+    <td><%=h merchandise.id %></td>
+    <td><%=link_to merchandise.title.to_s, :action => 'show', :id => merchandise %></td>
+    <td><%=h merchandise.quantity %></td>
+    <td><%=h number_to_currency(merchandise.price) %></td>
+    <td><%= link_to 'Edit', :action => 'edit', :id => merchandise %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => merchandise }, :confirm => 'Are you sure?', :method => :post %></td>
+  </tr>
+<% end %>
+</table>
+<% end %>
index a5be4fb..5297424 100644 (file)
@@ -2,17 +2,14 @@
 
 <table border="1">
   <tr>
-  <% for column in RentablePolicy.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
+    <th>Description</th>
+    <th>Quantity</th>
   </tr>
   
 <% for rentable_policy in @rentable_policies %>
   <tr>
-  <% for column in RentablePolicy.content_columns %>
-    <td><%=h rentable_policy.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'View', :action => 'show', :id => rentable_policy %></td>
+    <td><%=h rentable_policy.description %></td>
+    <td><%=h rentable_policy.value %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => rentable_policy %></td>
   </tr>
 <% end %>
index 539ca06..54acd88 100644 (file)
@@ -12,7 +12,6 @@
     <td><%=h video_policy.description %></td>
     <td><%=h number_to_currency(video_policy.fee) %></td>
     <td><%=h video_policy.period %> Days</td>
-    <td><%= link_to 'View', :action => 'show', :id => video_policy %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => video_policy %></td>
   </tr>
 <% end %>
index 9e6b130..413ba0b 100644 (file)
Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ