1

I have an app that uses the Carrierwave built-in multiple file uploaders. I'm trying to implement a basic image preview and management (only need to be able to remove selected image) with Jasny's Bootstrap File Input plugin, but am having no luck.

It works with one image, but not with multiple.

My models:

class Ad < ActiveRecord::Base
  mount_uploaders :images, AdImagesUploader

class AdImagesUploader < CarrierWave::Uploader::Base

My form:

= simple_form_for @ad do |f|
  - 5.times do |i|
    .fileinput.fileinput-new{"data-provides" => "fileinput"}
      .fileinput-preview.thumbnail{"data-trigger" => "fileinput", :style => "width: 200px; height: 150px;"}
      %div
        %span.btn.btn-default.btn-file
          %span.fileinput-new Selecione o Arquivo
          %span.fileinput-exists Change
          = f.file_field :images["#{i}"], multiple: true, limit: 4
          = f.hidden_field :images_cache
        %a.btn.btn-default.fileinput-exists{"data-dismiss" => "fileinput", :href => "#"} Remove

I want to either:

a. Display 5 inputs so the user can select each image and see the preview and remove using Jasny's plugin controls

OR

b. Display one button that generates 5 previews for each file the user tries to upload with a multiple selection.

The problem with 'a' is that I need to create 5 f.input :images and that does not work when the form is submitted.

The problem with 'b' is that it only shows the preview of the first image and only allows the controls to work on the first image.

I can't change the implementation of Carrierwave for now, so I need to work with that configuration. I can't implement a new model AdImages to use the regular CarrierWave upload.

Any ideas? I accept suggestions for other plugins or other ways to show previews USING CarrierWave's built-in multiplie upload feature.

EDIT: For those who don't know, CarrierWave creates a JSON column in the database to store the image filepaths. That's why I tried to manually insert :image[1] in the form.

Hugo Carlos
  • 401
  • 3
  • 22

0 Answers0