表单: RailsNotes
用户: dreamable
创建日期: 2021-04-29 22:11:37 UTC
更新日期: 2021-04-29 22:11:46 UTC
引用:(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
标签: