Customer.find(params[:id]).destroy
redirect_to :action => 'list'
end
+
+ def searchbyname
+ render :action => 'searchbyname'
+ end
+
+ def searchresults
+ query = params[:q]
+ @customers = Customer.find(:all, :conditions => ["name = ?", query])
+ end
end
--- /dev/null
+<h1>Search for a Customer by Name</h1>
+
+<%= start_form_tag :action => 'searchresults'%>
+<%= text_field 'q', nil %>
+ <%= submit_tag 'Search' %></form>
+<%= end_form_tag %>
+
+<br />
--- /dev/null
+<h1>Search Results</h1>
+
+<% if @customers.empty? %>
+<p>Sorry, there were no results</p>
+<% else %>
+<table>
+ <tr>
+ <th>Customer ID</th>
+ <% for column in Customer.content_columns %>
+ <th><%= column.human_name %></th>
+ <% end %>
+ </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><%= link_to 'Edit', :action => 'edit', :id => customer %></td>
+ <td><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :post => true %></td>
+ </tr>
+<% end %>
+</table>
+<% end %>