Class: Spree::Api::VariantsController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Spree::Api::VariantsController
- Defined in:
- app/controllers/spree/api/variants_controller.rb
Instance Attribute Summary
Attributes inherited from BaseController
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#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.
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/spree/api/variants_controller.rb', line 6 def create :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
16 17 18 19 20 |
# File 'app/controllers/spree/api/variants_controller.rb', line 16 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.
25 26 27 28 29 |
# File 'app/controllers/spree/api/variants_controller.rb', line 25 def index @variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }) .ransack(params[:q]).result.page(params[:page]).per(params[:per_page]) respond_with(@variants) end |
#new ⇒ Object
31 32 |
# File 'app/controllers/spree/api/variants_controller.rb', line 31 def new end |
#show ⇒ Object
34 35 36 37 38 |
# File 'app/controllers/spree/api/variants_controller.rb', line 34 def show @variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location }) .find(params[:id]) respond_with(@variant) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/spree/api/variants_controller.rb', line 40 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 |