Class: Spree::Api::CustomerReturnsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/customer_returns_controller.rb

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 12

def create
  authorize! :create, CustomerReturn

  if @customer_return.save
    respond_with(@customer_return, status: 201, default_template: :show)
  else
    invalid_resource!(@customer_return)
  end
end

#indexObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 22

def index
  authorize! :index, CustomerReturn

  @customer_returns = @order.
    customer_returns.
    accessible_by(current_ability).
    ransack(params[:q]).
    result

  @customer_returns = paginate(@customer_returns)

  respond_with(@customer_returns)
end

#newObject



36
37
38
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 36

def new
  authorize! :new, CustomerReturn
end

#showObject



40
41
42
43
44
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 40

def show
  authorize! :show, CustomerReturn
  @customer_return = @order.customer_returns.accessible_by(current_ability, :show).find(params[:id])
  respond_with(@customer_return)
end

#updateObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/spree/api/customer_returns_controller.rb', line 46

def update
  authorize! :update, CustomerReturn
  @customer_return = @order.customer_returns.accessible_by(current_ability, :update).find(params[:id])
  if @customer_return.update(customer_return_params)
    respond_with(@customer_return.reload, default_template: :show)
  else
    invalid_resource!(@customer_return)
  end
end