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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With