Class: Spree::Api::V1::VariantsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys
included
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
17
18
|
# File 'app/controllers/spree/api/v1/variants_controller.rb', line 17
def new
end
|
#show ⇒ Object
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
|
#update ⇒ Object
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
|