Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload multiple files with a single file_uploader rails 4

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 am using the gem nested_form_fields and paperclip in my app. Through the above code, I am able to upload multiple files. But my concern is how do I upload multiple files with a single file_uploader. I used name file[] and :multiple=>true, still its not working. Please help me out.

like image 403
Uday kumar das Avatar asked Jan 09 '23 05:01

Uday kumar das


1 Answers

I also needed same thing but didn't fine any solution. In my project I am using

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

User just have to select multiple files after selecting this field. And in controller I am able to get all those files with params[:image_files]

I am then building images as :

 # 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
like image 54
raviture Avatar answered Jan 21 '23 17:01

raviture