app/controllers/spree/api/images_controller.rb in spree_api-2.2.0 vs app/controllers/spree/api/images_controller.rb in spree_api-2.2.1

- old
+ new

@@ -7,28 +7,36 @@ respond_with(@image) end def create authorize! :create, Image - @image = Image.create(image_params) + @image = scope.images.create(image_params) respond_with(@image, :status => 201, :default_template => :show) end def update - @image = Image.accessible_by(current_ability, :update).find(params[:id]) + @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 = Image.accessible_by(current_ability, :destroy).find(params[:id]) + @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