Class: Spree::Api::V1::VariantsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/v1/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

Methods included from ControllerSetup

included

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 20

def create
  authorize! :create, Variant
  @variant = scope.new(params[:variant])
  if @variant.save
    render :show, :status => 201
  else
    invalid_resource!(@variant)
  end
end

#destroyObject



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

def destroy
  authorize! :delete, Variant
  @variant = scope.find(params[:id])
  @variant.destroy
  render :text => nil, :status => 204
end

#indexObject



7
8
9
10
11
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 7

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

#newObject



17
18
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 17

def new
end

#showObject



13
14
15
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 13

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

#updateObject



30
31
32
33
34
35
36
37
38
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 30

def update
  authorize! :update, Variant
  @variant = scope.find(params[:id])
  if @variant.update_attributes(params[:variant])
    render :show, :status => 200
  else
    invalid_resource!(@product)
  end
end