Sha256: ebc2bdadf226e2ec2694ee1f565389422cfe425e48dff09eba1fac8e2fbc77d0
Contents?: true
Size: 1.34 KB
Versions: 13
Compression:
Stored size: 1.34 KB
Contents
module Spree module Api module V1 class VariantsController < Spree::Api::V1::BaseController before_filter :product def index @variants = scope.includes(:option_values).scoped end def show @variant = scope.includes(:option_values).find(params[:id]) end def new end def create authorize! :create, Variant @variant = scope.new(params[:product]) if @variant.save render :show, :status => 201 else invalid_resource!(@variant) end end 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 def destroy authorize! :delete, Variant @variant = scope.find(params[:id]) @variant.destroy render :text => nil, :status => 200 end private def product @product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id] end def scope @product ? @product.variants_including_master : Variant end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems