Rails - input type = "file" multiple

I'm still looking for an elegant multi-file download for Rails.

I just found out about "input type =" file "multiple"

Does Rails support this? Any examples? implementation tips for uploading multiple photos to a photo album model in Rails?

thank

+3
source share
4 answers

What you need to do is sleep more like this:

<% = f.file_field: attachment: multiple => true%>

+2
source

It is easy on the rails. If you use form_for, do it like this:

form_for(@user, :html => {:multipart => true}) do |f|

If you do this with help form_tag, it works like this:

form_tag new_user_path, :multipart => true

Hope this helps!

+1

Here's the full snippet of working code for Rails 5:

<%= form_for(@user, html: {multipart: true}) do |f| %>
    <%= f.file_field :picture, accept: 'image/png,image/gif,image/jpeg,image/jpg', multiple: true %>
    <%= f.submit 'Upload Picture' %>
<% end %>           
0
source

Source: https://habr.com/ru/post/1771130/


All Articles