Upload multiple files with a single file_uploader 4 repository

In sr_documents/form:

<%= simple_form_for @service_request,:url=>upload_document_path(@service_request.id),:remote=>true,:html => { :multipart => true } do |f| %>

<%= f.nested_fields_for :sr_documents do |q| %>

<%= q.input :file,:required => true,:hint=>"(only .pdf,.docx,.doc,.txt)", multiple: true,:name=>'file[]' %>

<%= f.button :submit ,:class=> "btn btn-go button",data: {"disable-with" => "Processing..."}%>

<%= f.add_nested_fields_link :sr_documents,"Add new file" %>
<%end%>

I use the gem nested_form_fieldsand paperclipin its application. With the above code, I can upload multiple files. But I'm worried about how to upload multiple files using one file_uploader. I used the name file[]and :multiple=>true, but still does not work. Please help me.

+4
source share
1 answer

I also needed the same thing, but could not find any solution. In my project I use

= file_field_tag :image_files, :multiple => true, name: 'image_files[]', style: 'display:none', :id => 'fileinput'

The user simply has to select several files after selecting this field. And in the controller I can get all these files with parameters [: image_files]

:

 # This method builds images as per image_files params
  def build_images
    (params[:image_files] || []).each do |img|
      @product.images.build(file: img)
    end
  end
+4

All Articles