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
<% 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>
<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 %>
<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>
--- /dev/null
+<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 />
--- /dev/null
+<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 %>
<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 %>
<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 %>