Class: Spree::Api::VariantsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys, #set_jsonp_format
included
Instance Method Details
#create ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'app/controllers/spree/api/variants_controller.rb', line 22
def create
authorize! :create, Variant
@variant = scope.new(params[:variant])
if @variant.save
respond_with(@variant, :status => 201, :default_template => :show)
else
invalid_resource!(@variant)
end
end
|
#destroy ⇒ Object
42
43
44
45
46
47
|
# File 'app/controllers/spree/api/variants_controller.rb', line 42
def destroy
authorize! :delete, Variant
@variant = scope.find(params[:id])
@variant.destroy
respond_with(@variant, :status => 204)
end
|
#index ⇒ Object
8
9
10
11
12
|
# File 'app/controllers/spree/api/variants_controller.rb', line 8
def index
@variants = scope.includes(:option_values).ransack(params[:q]).result.
page(params[:page]).per(params[:per_page])
respond_with(@variants)
end
|
#new ⇒ Object
19
20
|
# File 'app/controllers/spree/api/variants_controller.rb', line 19
def new
end
|
#show ⇒ Object
14
15
16
17
|
# File 'app/controllers/spree/api/variants_controller.rb', line 14
def show
@variant = scope.includes(:option_values).find(params[:id])
respond_with(@variant)
end
|
#update ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'app/controllers/spree/api/variants_controller.rb', line 32
def update
authorize! :update, Variant
@variant = scope.find(params[:id])
if @variant.update_attributes(params[:variant])
respond_with(@variant, :status => 200, :default_template => :show)
else
invalid_resource!(@product)
end
end
|