Sha256: e32851e1b71243e027c5ea878637e11da601bbb132b9e3e2889d60580767db7a

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

module Shoppe
  class CustomersController < Shoppe::ApplicationController

    before_filter { @active_nav = :customers }  
    before_filter { params[:id] && @customer = Shoppe::Customer.find(params[:id])}

    def index
      @query = Shoppe::Customer.ordered.page(params[:page]).search(params[:q])
      @customers = @query.result
    end

    def new
      @customer = Shoppe::Customer.new
    end

    def show
      @addresses = @customer.addresses.ordered.load
      @orders = @customer.orders.ordered.load
    end

    def create
      @customer = Shoppe::Customer.new(safe_params)
      if @customer.save
        redirect_to @customer, :flash => {:notice => "Customer has been created successfully"}
      else
        render :action => "new"
      end
    end

    def update
      if @customer.update(safe_params)
        redirect_to @customer, :flash => {:notice => "Customer has been updated successfully"}
      else
        render :action => "edit"
      end
    end

    def destroy
      @customer.destroy
      redirect_to customers_path, :flash => {:notice => "Customer has been deleted successfully"}
    end

    def search
      index
      render :action => "index"
    end

    private
  
    def safe_params
      params[:customer].permit(:first_name, :last_name, :company, :email, :phone, :mobile)
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
shoppe-1.1.1 app/controllers/shoppe/customers_controller.rb
shoppe-1.1.0 app/controllers/shoppe/customers_controller.rb
shoppe-1.0.9 app/controllers/shoppe/customers_controller.rb
shoppe-1.0.8 app/controllers/shoppe/customers_controller.rb
kylekthompson-shoppe-1.0.7 app/controllers/shoppe/customers_controller.rb