Class: Shoppe::CustomersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
# File 'app/controllers/shoppe/customers_controller.rb', line 20

def create
  @customer = Shoppe::Customer.new(safe_params)
  if @customer.save
    redirect_to @customer, flash: { notice: t('shoppe.customers.created_successfully') }
  else
    render action: 'new'
  end
end

#destroyObject



37
38
39
40
# File 'app/controllers/shoppe/customers_controller.rb', line 37

def destroy
  @customer.destroy
  redirect_to customers_path, flash: { notice: t('shoppe.customers.deleted_successfully') }
end

#indexObject



6
7
8
9
# File 'app/controllers/shoppe/customers_controller.rb', line 6

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

#newObject



11
12
13
# File 'app/controllers/shoppe/customers_controller.rb', line 11

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

#searchObject



42
43
44
45
# File 'app/controllers/shoppe/customers_controller.rb', line 42

def search
  index
  render action: 'index'
end

#showObject



15
16
17
18
# File 'app/controllers/shoppe/customers_controller.rb', line 15

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

#updateObject



29
30
31
32
33
34
35
# File 'app/controllers/shoppe/customers_controller.rb', line 29

def update
  if @customer.update(safe_params)
    redirect_to @customer, flash: { notice: t('shoppe.customers.updated_successfully') }
  else
    render action: 'edit'
  end
end