From bbf13350a73e14c5448f6fb0077126b7d92cdb48 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sun, 25 Nov 2007 12:33:12 -0800 Subject: [PATCH] Prettify the Customer pages Signed-off-by: Ira W. Snyder --- app/controllers/customer_controller.rb | 19 ++++++++++--------- app/views/customer/index.rhtml | 8 ++++++++ app/views/customer/list.rhtml | 8 ++++---- .../{searchbyname.rhtml => search.rhtml} | 2 +- app/views/customer/searchresults.rhtml | 4 ++-- app/views/layouts/admin.rhtml | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 app/views/customer/index.rhtml rename app/views/customer/{searchbyname.rhtml => search.rhtml} (73%) diff --git a/app/controllers/customer_controller.rb b/app/controllers/customer_controller.rb index 1e560c0..296f64f 100644 --- a/app/controllers/customer_controller.rb +++ b/app/controllers/customer_controller.rb @@ -1,11 +1,11 @@ class CustomerController < ApplicationController + layout "admin" # Make sure that the user has logged in before they can take any action before_filter :authorize def index - list - render :action => 'list' + render :action => 'index' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) @@ -53,12 +53,13 @@ class CustomerController < ApplicationController redirect_to :action => 'list' end - def searchbyname - render :action => 'searchbyname' - end - - def searchresults - query = params[:q] - @customers = Customer.find(:all, :conditions => ["name like ?", query[0]+"%"] ) + def search + if request.post? + @query = params[:q] + @customers = Customer.find(:all, :conditions => ["name like ?", @query[0]+"%"]) + render :action => 'searchresults' + else + render :action => 'search' + end end end diff --git a/app/views/customer/index.rhtml b/app/views/customer/index.rhtml new file mode 100644 index 0000000..521b806 --- /dev/null +++ b/app/views/customer/index.rhtml @@ -0,0 +1,8 @@ +

Customer Maintenence

+ +

Actions

+ diff --git a/app/views/customer/list.rhtml b/app/views/customer/list.rhtml index 30ffdb6..c9bce2b 100644 --- a/app/views/customer/list.rhtml +++ b/app/views/customer/list.rhtml @@ -1,6 +1,6 @@ -

Listing customers

+

Listing Customers

- +
<% for column in Customer.content_columns %> @@ -14,9 +14,9 @@ <% for column in Customer.content_columns %> <% end %> - + - + <% end %>
Customer ID<%=h customer.send(column.name) %><%= link_to 'Show', :action => 'show', :id => customer %><%= link_to 'View', :action => 'show', :id => customer %> <%= link_to 'Edit', :action => 'edit', :id => customer %><%= link_to 'Destroy', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %><%= link_to 'Remove', { :action => 'destroy', :id => customer }, :confirm => 'Are you sure?', :method => :post %>
diff --git a/app/views/customer/searchbyname.rhtml b/app/views/customer/search.rhtml similarity index 73% rename from app/views/customer/searchbyname.rhtml rename to app/views/customer/search.rhtml index 7b17ec1..fd105b7 100644 --- a/app/views/customer/searchbyname.rhtml +++ b/app/views/customer/search.rhtml @@ -1,6 +1,6 @@

Search for a Customer by Name

-<%= start_form_tag :action => 'searchresults'%> +<%= start_form_tag :action => 'search'%> <%= text_field 'q', nil %> <%= submit_tag 'Search' %> <%= end_form_tag %> diff --git a/app/views/customer/searchresults.rhtml b/app/views/customer/searchresults.rhtml index a6488ce..cc32efe 100644 --- a/app/views/customer/searchresults.rhtml +++ b/app/views/customer/searchresults.rhtml @@ -1,9 +1,9 @@ -

Search Results

+

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

<% if @customers.empty? %>

Sorry, there were no results

<% else %> - +
<% for column in Customer.content_columns %> diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml index aba2ff5..a4ad91a 100644 --- a/app/views/layouts/admin.rhtml +++ b/app/views/layouts/admin.rhtml @@ -19,7 +19,7 @@

<%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %>

<%= link_to "Game Maintenence", :controller => 'game', :action => 'index' %>

<%= link_to "Checked Out Items", :controller => 'coitem', :action => 'index' %>

-

<%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %>

+

<%= link_to "Customer Maintenence", :controller => 'customer', :action => 'index' %>


<%= link_to "Logout", :controller => 'login', :action => 'logout' %>

-- 2.25.1
Customer ID