Class: Spree::Api::VariantsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #permitted_line_item_attributes, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#createObject



7
8
9
10
11
12
13
14
15
# File 'app/controllers/spree/api/variants_controller.rb', line 7

def create
  authorize! :create, Variant
  @variant = scope.new(variant_params)
  if @variant.save
    respond_with(@variant, status: 201, default_template: :show)
  else
    invalid_resource!(@variant)
  end
end

#destroyObject



17
18
19
20
21
# File 'app/controllers/spree/api/variants_controller.rb', line 17

def destroy
  @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
  @variant.destroy
  respond_with(@variant, status: 204)
end

#indexObject



23
24
25
26
27
# File 'app/controllers/spree/api/variants_controller.rb', line 23

def index
  @variants = scope.includes(:option_values).ransack(params[:q]).result.
    page(params[:page]).per(params[:per_page])
  respond_with(@variants)
end

#newObject



29
30
# File 'app/controllers/spree/api/variants_controller.rb', line 29

def new
end

#showObject



32
33
34
35
# File 'app/controllers/spree/api/variants_controller.rb', line 32

def show
  @variant = scope.includes(:option_values).find(params[:id])
  respond_with(@variant)
end

#updateObject



37
38
39
40
41
42
43
44
# File 'app/controllers/spree/api/variants_controller.rb', line 37

def update
  @variant = scope.accessible_by(current_ability, :update).find(params[:id])
  if @variant.update_attributes(variant_params)
    respond_with(@variant, status: 200, default_template: :show)
  else
    invalid_resource!(@product)
  end
end