Class: Admin::CustomersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/tang/admin/customers_controller.rb

Instance Method Summary collapse

Instance Method Details

#apply_couponObject



41
42
43
44
45
46
# File 'app/controllers/tang/admin/customers_controller.rb', line 41

def apply_coupon
  @customer = Tang.customer_class.find(params[:customer_id])
  @coupon = Coupon.find(params[Tang.customer_class.to_s.downcase][:coupon_id])
  ApplyCustomerDiscount.call(@customer, @coupon)
  redirect_to admin_customer_url(@customer), notice: 'Coupon was successfully applied.'
end

#couponObject



37
38
39
# File 'app/controllers/tang/admin/customers_controller.rb', line 37

def coupon
  @customer = Tang.customer_class.find(params[:customer_id])
end

#destroyObject

DELETE /customers/1



32
33
34
35
# File 'app/controllers/tang/admin/customers_controller.rb', line 32

def destroy
  @customer.destroy
  redirect_to admin_customers_url, notice: 'Customer was successfully destroyed.'
end

#editObject

GET /customers/1/edit



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

def edit; end

#indexObject

GET /customers



8
9
10
11
12
13
# File 'app/controllers/tang/admin/customers_controller.rb', line 8

def index
  @customers = Tang.customer_class
                   .where.not(stripe_id: nil)
                   .paginate(page: params[:page])
                   .order(:email)
end

#remove_couponObject



48
49
50
51
52
# File 'app/controllers/tang/admin/customers_controller.rb', line 48

def remove_coupon
  @customer = Tang.customer_class.find(params[:customer_id])
  RemoveCustomerDiscount.call(@customer)
  redirect_to admin_customer_url(@customer), notice: 'Coupon was successfully removed.'
end

#showObject

GET /customers/1



16
# File 'app/controllers/tang/admin/customers_controller.rb', line 16

def show; end

#updateObject

PATCH/PUT /customers/1



22
23
24
25
26
27
28
29
# File 'app/controllers/tang/admin/customers_controller.rb', line 22

def update
  if @customer.update(customer_params)
    UpdateCustomer.call(@customer)
    redirect_to admin_customer_path(@customer), notice: 'Customer was successfully updated.'
  else
    render :edit
  end
end