Sha256: 4bedbfef5558e6f1c675981dd6463d08c8a8e95e90f9070029459664c615be1f

Contents?: true

Size: 1.59 KB

Versions: 58

Compression:

Stored size: 1.59 KB

Contents

module Spree
  module Api
    class OptionValuesController < Spree::Api::BaseController
      def index
        if params[:ids]
          @option_values = scope.where(:id => params[:ids])
        else
          @option_values = scope.ransack(params[:q]).result
        end
        respond_with(@option_values)
      end

      def show
        @option_value = scope.find(params[:id])
        respond_with(@option_value)
      end

      def create
        authorize! :create, Spree::OptionValue
        @option_value = scope.new(option_value_params)
        if @option_value.save
          render :show, :status => 201
        else
          invalid_resource!(@option_value)
        end
      end

      def update
        @option_value = scope.accessible_by(current_ability, :update).find(params[:id])
        if @option_value.update_attributes(option_value_params)
          render :show
        else
          invalid_resource!(@option_value)
        end
      end

      def destroy
        @option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])
        @option_value.destroy
        render :text => nil, :status => 204
      end

      private

        def scope
          if params[:option_type_id]
            @scope ||= Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :read)
          else
            @scope ||= Spree::OptionValue.accessible_by(current_ability, :read).load
          end
        end

        def option_value_params
          params.require(:option_value).permit(permitted_option_value_attributes)
        end
    end
  end
end

Version data entries

58 entries across 58 versions & 2 rubygems

Version Path
solidus_api-1.0.7 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.6 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.5 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.4 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.3 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.2 app/controllers/spree/api/option_values_controller.rb
spree_api-2.4.10 app/controllers/spree/api/option_values_controller.rb
spree_api-2.3.13 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.1 app/controllers/spree/api/option_values_controller.rb
spree_api-2.2.14 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.0 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.0.rc2 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.0.rc1 app/controllers/spree/api/option_values_controller.rb
spree_api-2.4.9 app/controllers/spree/api/option_values_controller.rb
spree_api-2.3.12 app/controllers/spree/api/option_values_controller.rb
spree_api-2.2.13 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.0.pre3 app/controllers/spree/api/option_values_controller.rb
solidus_api-1.0.0.pre2 app/controllers/spree/api/option_values_controller.rb
spree_api-2.4.8 app/controllers/spree/api/option_values_controller.rb
spree_api-2.3.11 app/controllers/spree/api/option_values_controller.rb