I added an upload form so people can upload HTML files to my site. How do I allow multiple uploads at once? I added the jquery-fileupload-rails gem which lets the user select multiple files. However, only one file gets processed by the server. How do I fix this?

我添加了一个上传表单,这样人们就可以将HTML文件上传到我的站点。如何同时允许多个上传?我添加了jquery-fileupload-rails gem,它允许用户选择多个文件。但是,服务器只处理一个文件。我怎么修复这个?

More Details

更多的细节

My code is below, based on this Railscast. Note I'm not dealing with a model in the form, so I use field_tags instead. I didn't add name to file_field_tag, since it's name didn't change after adding files, though that may be part of the problem.

我的代码在下面,基于这个Railscast。注意,我不是在处理表单中的模型,所以我使用field_tags代替。我没有向file_field_tag添加名称,因为它的名称在添加文件后没有更改,尽管这可能是问题的一部分。

<%= form_tag import_items_path, multipart: true, id: "upload" do %>
    <%= file_field_tag :file, multiple: true %>
    <%= submit_tag "Import" %>
<% end %> 

And here's some the JS for the fileupload jQuery:

下面是fileupload jQuery的一些JS:

jQuery ->
  $('#upload').fileupload

When I add 2 files and click upload, only 1 file gets processed. Here's the log:

当我添加两个文件并单击upload时,只有一个文件被处理。日志:

Parameters: {"utf8"=>"✓", "file"=> #< ActionDispatch::Http::UploadedFile:0x... @tempfile=#< Tempfile:/var/folders/gl/...>, @original_filename="sample.html", @content_type="text/html",... name=\"file\"; filename=\"sample.html\"...}

参数:{“use utf8”= >“✓”、“文件”= > # < Http ActionDispatch::::UploadedFile:0 x……@tempfile = # < Tempfile:/ var /文件夹/ gl /…>,@original_filename = "样本。html”,@content_type = " text / html ",……name = \ \“文件”;sample . html文件名= \“\”…}

I tried ajaxifying the form, but that didn't help either. How can I get jquery-fileupload-rails in Rails 4 to work?

我试着对表单进行ajax化,但这也无济于事。如何在Rails 4中获得jquery- fileuploadrails ?

1 个解决方案

#1


3

If you change <%= file_field_tag :file, multiple: true %> to <%= file_field_tag 'files[]', multiple: true %> it should work.

如果您将<%= file_field_tag:file, multiple: true %>改为<%= file_field_tag 'files[], multiple: true %>,应该可以工作。

See this related SO post.

见此相关帖。

更多相关文章

  1. Asp。NET MVC Ajax-Post表单和Ajax-Get
  2. 使用jquery post发布PHP文件
  3. 解析jquery实现回车键提交表单
  4. JQUERY中做表单验证,谁有带时间的日期选择控件?
  5. 深入学习jQuery选择器系列第七篇——表单选择器
  6. jQuery Validate 表单验证插件
  7. 如何将表单转换成json通过AJAX传递?
  8. 从JQuery文件输入中获取数据
  9. jQuery LightBox(SlimBox):如何在其中填充ASPX文件?

随机推荐

  1. 你知道golang中Context的使用场景有哪些
  2. 关于 Golang 字符串 格式化
  3. 关于golang读写锁
  4. 关于golang之排序使用
  5. 【发布了Go-carbon1.1.1版本】完善对主流
  6. 关于Go语言的http/2服务器功能及客户端使
  7. 关于Go SQL中的Query、Exec和Prepare使用
  8. 教你使用Golang和lua实现一个值班机器人
  9. gin框架有什么优势
  10. windows10下编译go项目为linux可执行文件