Class: CustomersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/customers_controller.rb

Overview

The customers controller.

Instance Method Summary (collapse)

Instance Method Details

- (Object) create

POST /customers POST /customers.json



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/customers_controller.rb', line 33

def create
  @customer = Customer.new(customer_params)

  respond_to do |format|
    if @customer.save
      format.html { redirect_to @customer, notice: 'Customer was successfully created.' }
      format.json { render action: 'show', status: :created, location: @customer }
    else
      format.html { render action: 'new' }
      format.json { render json: @customer.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) destroy

DELETE /customers/1 DELETE /customers/1.json



63
64
65
66
67
68
69
# File 'app/controllers/customers_controller.rb', line 63

def destroy
  @customer.destroy
  respond_to do |format|
    format.html { redirect_to customers_url }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /customers/1/edit



28
29
# File 'app/controllers/customers_controller.rb', line 28

def edit
end

- (Object) index

GET /customers GET /customers.json



9
10
11
12
13
14
15
# File 'app/controllers/customers_controller.rb', line 9

def index
  if current_customer.role == 'admin'
    @customers = Customer.all
  else
    @customers = Customer.where('id = ?', current_customer.id)
  end
end

- (Object) new

GET /customers/new



23
24
25
# File 'app/controllers/customers_controller.rb', line 23

def new
  @customer = Customer.new
end

- (Object) show

GET /customers/1 GET /customers/1.json



19
20
# File 'app/controllers/customers_controller.rb', line 19

def show
end

- (Object) update

PATCH/PUT /customers/1 PATCH/PUT /customers/1.json



49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/customers_controller.rb', line 49

def update
  respond_to do |format|
    if @customer.update(customer_params)
      format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @customer.errors, status: :unprocessable_entity }
    end
  end
end