Table: RailsNotes
User: dreamable
Created at: 2021-04-29 22:11:37 UTC
Updated at: 2021-04-29 22:11:46 UTC
Reference:(Table ID 3, Record ID 43)

标题 :
Rails Upload Multiple Files
笔记 :

guide

  • View: enable multiple
      <% if false %>
        <-- Not work: InvalidSignature -->
        <%= file_field_tag('files[]',class: "form-control", multiple: true, id: :files) %>
      <% end %>
      <%= form.file_field :files, class: "form-control", multiple: true %>
  • Controller: handle array
      @folder = Folder.find(params[:folder_id]) if params[:folder_id].present?
      (params[:files]||[]).each do |f|
        ps = {note: params[:note], file: f, user_id: current_user.id, folder: @folder}
        @document = Document.create(ps)
      end
Tag: