Class CustomerController
In: app/controllers/customer_controller.rb
Parent: ApplicationController

************************************************************************/

  • SOLUNAS BOOKING ENGINE */
  • ====================== */
  • */
  • Copyright © 2006 by Marc Isemann */
  • sourceforge.net/projects/solunas */
  • */
  • This program is free software. You can redistribute it and/or modify */
  • it under the terms of the GNU General Public License as published by */
  • the Free Software Foundation; either version 2 of the License. */

************************************************************************/

Methods

create   destroy   edit   index   list   new   search   show   update  

Public Instance methods

Create new customer in database

[Source]

    # File app/controllers/customer_controller.rb, line 50
50:   def create
51:     @customer = Customer.new(params[:customer])
52:         @customer.user_id = session[:user_id];
53:     if @customer.save
54:       flash[:notice] = 'Customer was successfully created.'
55:       redirect_to :action => 'list'
56:     else
57:       render :action => 'new'
58:     end
59:   end

Destroy existing customer and all contracts. Redirect to list customers

[Source]

    # File app/controllers/customer_controller.rb, line 79
79:   def destroy
80:     Contract.delete_all(["customer_id = ?", params[:id]])
81:     Customer.find(params[:id]).destroy
82:     redirect_to :action => 'list'
83:   end

Show form to edit customer. ID is needed.

[Source]

    # File app/controllers/customer_controller.rb, line 62
62:   def edit
63:     @customer = Customer.find(params[:id])
64:   end

Index page: List all customers

[Source]

    # File app/controllers/customer_controller.rb, line 19
19:   def index
20:     list
21:     render :action => 'list'
22:   end

List all customers. Filter user_id

[Source]

    # File app/controllers/customer_controller.rb, line 29
29:   def list
30:     if params[:search]
31:     @customer_pages, @customers = paginate :customer, :per_page => 10,
32:                                                       :conditions => ["name like ? && user_id = ?","%#{params[:search]}%", session[:user_id]]
33:     else
34:     @customer_pages, @customers = paginate :customer, :per_page => 10,
35:                                                       :conditions => ["user_id = ?",session[:user_id]]
36:     end
37:   end

Show form to create new customer

[Source]

    # File app/controllers/customer_controller.rb, line 45
45:   def new
46:     @customer = Customer.new
47:   end

Search for a customer. Searchable database fields: name

[Source]

    # File app/controllers/customer_controller.rb, line 25
25:   def search
26:   end

Show one customer in detail. ID is needed.

[Source]

    # File app/controllers/customer_controller.rb, line 40
40:   def show
41:     @customer = Customer.find(params[:id])
42:   end

Update existing customer in database. Redirect to show customer

[Source]

    # File app/controllers/customer_controller.rb, line 67
67:   def update
68:     @customer = Customer.find(params[:id])
69:     @customer.user_id = session[:user_id];
70:     if @customer.update_attributes(params[:customer])
71:       flash[:notice] = 'Customer was successfully updated.'
72:       redirect_to :action => 'show', :id => @customer
73:     else
74:       render :action => 'edit'
75:     end
76:   end

[Validate]