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



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

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



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

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

#destroyObject

DELETE /customers/1



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

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

#editObject

GET /customers/1/edit



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

def edit
end

#indexObject

GET /customers



8
9
10
11
12
# 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



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

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



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

def show
end

#updateObject

PATCH/PUT /customers/1



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

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