Class: Spree::Api::V1::VariantsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#content_type, #permitted_line_item_attributes
included
Instance Method Details
#create ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'app/controllers/spree/api/v1/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
|
#destroy ⇒ Object
17
18
19
20
21
|
# File 'app/controllers/spree/api/v1/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
|
#index ⇒ Object
The lazyloaded associations here are pretty much attached to which nodes we render on the view so we better update it any time a node is included or removed from the views.
26
27
28
29
30
|
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 26
def index
@variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
respond_with(@variants)
end
|
#new ⇒ Object
32
|
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 32
def new; end
|
#show ⇒ Object
34
35
36
37
|
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 34
def show
@variant = scope.includes(*variant_includes).find(params[:id])
respond_with(@variant)
end
|
#update ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 39
def update
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
if @variant.update(variant_params)
respond_with(@variant, status: 200, default_template: :show)
else
invalid_resource!(@product)
end
end
|