From: Ira W. Snyder Date: Thu, 22 Nov 2007 05:23:20 +0000 (-0800) Subject: Add customer searching capability X-Git-Tag: turned-in~72 X-Git-Url: https://www.irasnyder.com/gitweb/?p=cs356-p2-videostore.git;a=commitdiff_plain;h=c9f35305eb2750116e7a073265ea6f1081226895 Add customer searching capability This allows simple customer searching by name. Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/customer_controller.rb b/app/controllers/customer_controller.rb index 6f7c8ee..d741644 100644 --- a/app/controllers/customer_controller.rb +++ b/app/controllers/customer_controller.rb @@ -48,4 +48,13 @@ class CustomerController < ApplicationController 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 diff --git a/app/views/customer/searchbyname.rhtml b/app/views/customer/searchbyname.rhtml new file mode 100644 index 0000000..7b17ec1 --- /dev/null +++ b/app/views/customer/searchbyname.rhtml @@ -0,0 +1,8 @@ +

Search for a Customer by Name

+ +<%= start_form_tag :action => 'searchresults'%> +<%= text_field 'q', nil %> + <%= submit_tag 'Search' %> +<%= end_form_tag %> + +
diff --git a/app/views/customer/searchresults.rhtml b/app/views/customer/searchresults.rhtml new file mode 100644 index 0000000..a6488ce --- /dev/null +++ b/app/views/customer/searchresults.rhtml @@ -0,0 +1,26 @@ +

Search Results

+ +<% if @customers.empty? %> +

Sorry, there were no results

+<% else %> + + + + <% for column in Customer.content_columns %> + + <% end %> + + +<% for customer in @customers %> + + + <% for column in Customer.content_columns %> + + <% end %> + + + + +<% end %> +
Customer ID<%= column.human_name %>
<%=h customer.id %><%=h customer.send(column.name) %><%= link_to 'Show', :action => 'show', :id => customer %><%= link_to 'Edit', :action => 'edit', :id => customer %><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :post => true %>
+<% end %>