SS
Size: a a a
SS
SS
SS
s
module Spree
module Admin
class ImagesController < ResourceController
before_action :load_edit_data, except: :index
before_action :load_index_data, only: :index
create.before :set_viewable
update.before :set_viewable
private
def location_after_destroy
admin_product_images_url(@product)
end
def location_after_save
admin_product_images_url(@product)
end
def load_index_data
@product = Product.friendly.includes(*variant_index_includes).find(params[:product_id])
end
def load_edit_data
@product = Product.friendly.includes(*variant_edit_includes).find(params[:product_id])
@variants = @product.variants.map do |variant|
[variant.sku_and_options_text, variant.id]
end
@variants.insert(0, [Spree.t(:all), @product.master.id])
end
def set_viewable
@image.viewable_type = 'Spree::Variant'
@image.viewable_id = params[:image][:viewable_id]
end
def variant_index_includes
[
variant_images: [viewable: { option_values: :option_type }]
]
end
def variant_edit_includes
[
variants_including_master: { option_values: :option_type, images: :viewable }
]
end
end
end
end
PM
{"authenticity_token"=>"+OLфыsdfsdfTg+cqCMk0L+g1/WFk2MtWANGclYhhMfZ/baCxC/9nnSXq33DamKXNQQ==",он половину дела вроде делает
"image"=>
{"attachment"=>
#<ActionDispatch::Http::UploadedFile:0x00007faa12ef9fc0
@content_type="image/jpeg",
@headers=
"Content-Disposition: form-data; name=\"image[attachment]\"; filename=\"\xD0\x91\xD0\xB5\xD0\xB7 \xD0\xBD\xD0\xB0\xD0\xB7\xD0\xB2\xD0\xB0\xD0\xBD\xD0\xB8\xD1\x8F.jpg\"\r\n" +
"Content-Type: image/jpeg\r\n",
@original_filename="Без названия.jpg",
@tempfile=#<File:/tmp/RackMultipart20200826-65620-1i7ylzn.jpg>>,
"viewable_id"=>"741",
"alt"=>""},
"button"=>"",
"product_id"=>"essential_henley_t-shirt-136"}
s
s
D‘
SP
D‘
AB
D‘
D‘
RN
AB
AB
D‘
AB
D‘
AB