Class: Spree::Admin::PaymentMethodsController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/admin/payment_methods_controller.rb

Instance Method Summary collapse

Methods inherited from ResourceController

belongs_to, #destroy, #edit, #new, #update_positions

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/admin/payment_methods_controller.rb', line 12

def create
  @payment_method = @payment_method_type.new(payment_method_params)
  @object = @payment_method
  invoke_callbacks(:create, :before)
  if @payment_method.save
    invoke_callbacks(:create, :after)
    flash[:success] = t('spree.successfully_created', resource: t('spree.payment_method'))
    redirect_to edit_admin_payment_method_path(@payment_method)
  else
    invoke_callbacks(:create, :fails)
    respond_with(@payment_method)
  end
end

#updateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/spree/admin/payment_methods_controller.rb', line 26

def update
  @payment_method = @payment_method.becomes(@payment_method_type)
  invoke_callbacks(:update, :before)

  attributes = payment_method_params
  attributes.each do |key, _value|
    if key.include?("password") && attributes[key].blank?
      attributes.delete(key)
    end
  end

  if @payment_method.update(attributes)
    invoke_callbacks(:update, :after)
    flash[:success] = t('spree.successfully_updated', resource: t('spree.payment_method'))
    redirect_to edit_admin_payment_method_path(@payment_method)
  else
    invoke_callbacks(:update, :fails)
    respond_with(@payment_method)
  end
end