Class: Effective::CustomersController

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

Instance Method Summary collapse

Instance Method Details

#editObject

Get here by visiting /customer/settings



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

def edit
  @customer = Effective::Customer.where(user: current_user).first!
  EffectiveOrders.authorize!(self, :edit, @customer)

  @subscripter = Effective::Subscripter.new(customer: @customer, user: @customer.user)

  @page_title ||= "Customer #{current_user.to_s}"
end

#updateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/effective/customers_controller.rb', line 17

def update
  @customer = Effective::Customer.where(user: current_user).first!
  EffectiveOrders.authorize!(self, :update, @customer)

  @subscripter = Effective::Subscripter.new(customer: @customer, user: @customer.user)
  @subscripter.assign_attributes(subscripter_params)

  @page_title ||= "Customer #{current_user.to_s}"

  if (@subscripter.save! rescue false)
    flash[:success] = "Successfully updated customer settings"
    redirect_to(effective_orders.customer_settings_path)
  else
    flash.now[:danger] = "Unable to update customer settings: #{@subscripter.errors.full_messages.to_sentence}"
    render :edit
  end
end