Sha256: eb4bc48138a353fcbf9832e93b4e72714e679d91f7a600a82e7cf8246e88ee88

Contents?: true

Size: 1.16 KB

Versions: 28

Compression:

Stored size: 1.16 KB

Contents

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

      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

28 entries across 28 versions & 1 rubygems

Version Path
spree_api-2.3.13 app/controllers/spree/api/images_controller.rb
spree_api-2.2.14 app/controllers/spree/api/images_controller.rb
spree_api-2.3.12 app/controllers/spree/api/images_controller.rb
spree_api-2.2.13 app/controllers/spree/api/images_controller.rb
spree_api-2.3.11 app/controllers/spree/api/images_controller.rb
spree_api-2.2.12 app/controllers/spree/api/images_controller.rb
spree_api-2.3.10 app/controllers/spree/api/images_controller.rb
spree_api-2.3.9 app/controllers/spree/api/images_controller.rb
spree_api-2.2.11 app/controllers/spree/api/images_controller.rb
spree_api-2.2.10 app/controllers/spree/api/images_controller.rb
spree_api-2.3.8 app/controllers/spree/api/images_controller.rb
spree_api-2.3.7 app/controllers/spree/api/images_controller.rb
spree_api-2.2.9 app/controllers/spree/api/images_controller.rb
spree_api-2.3.6 app/controllers/spree/api/images_controller.rb
spree_api-2.2.8 app/controllers/spree/api/images_controller.rb
spree_api-2.3.5 app/controllers/spree/api/images_controller.rb
spree_api-2.2.7 app/controllers/spree/api/images_controller.rb
spree_api-2.3.4 app/controllers/spree/api/images_controller.rb
spree_api-2.2.6 app/controllers/spree/api/images_controller.rb
spree_api-2.3.3 app/controllers/spree/api/images_controller.rb