Sha256: 0f00718506eaffeb2c0068653b78427338cadc2f68b29da4a3f3ce1ec792c547

Contents?: true

Size: 1.29 KB

Versions: 42

Compression:

Stored size: 1.29 KB

Contents

module Spree
  module Api
    class ImagesController < Spree::Api::BaseController

      def index
        @images = scope.images.accessible_by(current_ability, :read)
        respond_with(@images)
      end

      def show
        @image = Image.accessible_by(current_ability, :read).find(params[:id])
        respond_with(@image)
      end

      def create
        authorize! :create, Image
        @image = scope.images.create(image_params)
        respond_with(@image, :status => 201, :default_template => :show)
      end

      def update
        @image = scope.images.accessible_by(current_ability, :update).find(params[:id])
        @image.update_attributes(image_params)
        respond_with(@image, :default_template => :show)
      end

      def destroy
        @image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
        @image.destroy
        respond_with(@image, :status => 204)
      end

      private
        def image_params
          params.require(:image).permit(permitted_image_attributes)
        end

        def scope
          if params[:product_id]
            scope = Spree::Product.friendly.find(params[:product_id])
          elsif params[:variant_id]
            scope = Spree::Variant.find(params[:variant_id])
          end
        end
    end
  end
end

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
solidus_api-1.2.3 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.4 app/controllers/spree/api/images_controller.rb
solidus_api-1.0.7 app/controllers/spree/api/images_controller.rb
solidus_api-1.0.6 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.2 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.1 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.3 app/controllers/spree/api/images_controller.rb
solidus_api-1.0.5 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.0 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.0.rc2 app/controllers/spree/api/images_controller.rb
solidus_api-1.0.4 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.2 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.0.rc1 app/controllers/spree/api/images_controller.rb
solidus_api-1.2.0.beta1 app/controllers/spree/api/images_controller.rb
solidus_api-1.0.3 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.1 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.0 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.0.pre2 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.0.pre1 app/controllers/spree/api/images_controller.rb
solidus_api-1.1.0.beta1 app/controllers/spree/api/images_controller.rb