samedi 13 février 2016

activeadmin carrierwave multiple input: preview existing picture

I implement native carrierwave multiple uploaders to activeadmin. Images saving to database correctly. And I can preview existing image in FORM for single input, this way:

f.input :background, :as => :file, :hint => image_tag(f.object.background.url(:thumb)`)

but I cannot preview existing images in FORM for multiple input:

f.input :images, as: :file, input_html: { multiple: true}, :hint => f.object.images.each {|i| image_tag(i.url(:thumb))}

And its render nothing in web browser. But if I put this code into content_tag:

f.input :images, as: :file, input_html: { multiple: true}, :hint => content_tag(:div, f.object.images.each {|i| image_tag(i.url(:thumb))})

It give me something like that:

[#<ProductAdditionalImagesUploader:0x007f5f430339d8 @model=#<Basrelief id: 1,
title: "Барельеф", description: "Барельеф...",
price_m: #<BigDecimal:7f5f42042600,'0.1E4',9(18)>,
created_at: "2016-02-07 22:31:34", updated_at: "2016-02-12 23:42:02",
background: "Bar_8.jpg", images: ["1.jpg", "2.jpg"]>, @mounted_as=:images,
@storage=#<CarrierWave::Storage::File:0x007f5f43033938
@uploader=#<ProductAdditionalImagesUploader:0x007f5f430339d8...

I want to note, that in SHOW, I can preview this images this way:

 row :images do
        ul do
          basrelief.images.each do |image|
            li do
              image_tag image.url(:thumb)
            end
          end
        end
      end

What I am doing wrong? Maybe there are another methods.

Aucun commentaire:

Enregistrer un commentaire