From: Ira W. Snyder Date: Tue, 27 Nov 2007 09:02:31 +0000 (-0800) Subject: Small Cleanups + Merchandise Search X-Git-Tag: turned-in X-Git-Url: https://www.irasnyder.com/gitweb/?p=cs356-p2-videostore.git;a=commitdiff_plain;h=15ecb2f306cff2808bdf635b0aba81f996dc80f6 Small Cleanups + Merchandise Search Signed-off-by: Ira W. Snyder --- diff --git a/app/controllers/merchandise_controller.rb b/app/controllers/merchandise_controller.rb index 79a85dd..f819b30 100644 --- a/app/controllers/merchandise_controller.rb +++ b/app/controllers/merchandise_controller.rb @@ -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 diff --git a/app/views/customer/searchresults.rhtml b/app/views/customer/searchresults.rhtml index cc32efe..37d8b2e 100644 --- a/app/views/customer/searchresults.rhtml +++ b/app/views/customer/searchresults.rhtml @@ -5,21 +5,21 @@ <% 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 %>Customer IDNamePhoneBalance
<%=h customer.id %><%=h customer.send(column.name) %><%= link_to 'Show', :action => 'show', :id => customer %><%=h customer.id %><%=link_to customer.name.to_s, :action => 'show', :id => customer %><%=h customer.phone %><%=h number_to_currency(customer.debt) %><%= link_to "Checked Out Items", :controller => :coitem, :action => 'filterbycustomerid', :id => customer %> <%= link_to 'Edit', :action => 'edit', :id => customer %><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :post => true %><%= link_to 'Remove', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %>
diff --git a/app/views/game_policy/list.rhtml b/app/views/game_policy/list.rhtml index 327c35d..fdcaa05 100644 --- a/app/views/game_policy/list.rhtml +++ b/app/views/game_policy/list.rhtml @@ -12,7 +12,6 @@ <%=h game_policy.description %> <%=h number_to_currency(game_policy.fee) %> <%=h game_policy.period %> Days - <%= link_to 'View', :action => 'show', :id => game_policy %> <%= link_to 'Edit', :action => 'edit', :id => game_policy %> <% end %> diff --git a/app/views/merchandise/index.rhtml b/app/views/merchandise/index.rhtml index 6950e28..1abaee6 100644 --- a/app/views/merchandise/index.rhtml +++ b/app/views/merchandise/index.rhtml @@ -3,5 +3,6 @@

Actions

diff --git a/app/views/merchandise/search.rhtml b/app/views/merchandise/search.rhtml new file mode 100644 index 0000000..142d401 --- /dev/null +++ b/app/views/merchandise/search.rhtml @@ -0,0 +1,8 @@ +

Search for a Merchandise by Name

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

Search Results for '<%= @query[0].to_s %>'

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

Sorry, there were no results

+<% else %> + + + + + + + + +<% for merchandise in @merchandises %> + + + + + + + + +<% end %> +
Merchandise IDTitleQuantity RemainingPrice Per Unit
<%=h merchandise.id %><%=link_to merchandise.title.to_s, :action => 'show', :id => merchandise %><%=h merchandise.quantity %><%=h number_to_currency(merchandise.price) %><%= link_to 'Edit', :action => 'edit', :id => merchandise %><%= link_to 'Remove', { :action => 'destroy', :id => merchandise }, :confirm => 'Are you sure?', :method => :post %>
+<% end %> diff --git a/app/views/rentable_policy/list.rhtml b/app/views/rentable_policy/list.rhtml index a5be4fb..5297424 100644 --- a/app/views/rentable_policy/list.rhtml +++ b/app/views/rentable_policy/list.rhtml @@ -2,17 +2,14 @@ - <% for column in RentablePolicy.content_columns %> - - <% end %> + + <% for rentable_policy in @rentable_policies %> - <% for column in RentablePolicy.content_columns %> - - <% end %> - + + <% end %> diff --git a/app/views/video_policy/list.rhtml b/app/views/video_policy/list.rhtml index 539ca06..54acd88 100644 --- a/app/views/video_policy/list.rhtml +++ b/app/views/video_policy/list.rhtml @@ -12,7 +12,6 @@ - <% end %> diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 9e6b130..413ba0b 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ
<%= column.human_name %>DescriptionQuantity
<%=h rentable_policy.send(column.name) %><%= link_to 'View', :action => 'show', :id => rentable_policy %><%=h rentable_policy.description %><%=h rentable_policy.value %> <%= link_to 'Edit', :action => 'edit', :id => rentable_policy %>
<%=h video_policy.description %> <%=h number_to_currency(video_policy.fee) %> <%=h video_policy.period %> Days<%= link_to 'View', :action => 'show', :id => video_policy %> <%= link_to 'Edit', :action => 'edit', :id => video_policy %>