【问题标题】:Enabling Async file uploads with jQuery File Upload + Carrierwave + Rails 4使用 jQuery File Upload + Carrierwave + Rails 4 启用异步文件上传
【发布时间】:2015-01-19 12:46:57
【问题描述】:

我正在尝试允许用户在文件上传时在门户中移动。

这是我的表单代码:

<%= form_for [@myfolder, Myfile.new], html: { multipart: true, :id => "fileupload" }, :remote => true, do |f| %>
<%= f.file_field :attachment, multiple: true, style: "display:none;" %>
<% end %>

它正在执行创建操作 (POST),该操作使用 JSON 输出进行响应。

format.html { redirect_to @parentfolder, notice: 'Your file was successfully created.' }
format.js
format.json{ render :show, status: :created, location: @myfile }

这是我的 application.js 中的 jquery 文件上传调用:

add: function(e, data) {
     data.context = $(tmpl("template-upload",data.files[0]))
     $('#fileupload').append(data.context)
     $('#inline-upload-status').show();
     $.getJSON('/myfiles.json', function (result) {
        data.formData = result; // e.g. {id: 123}
        data.submit();
     });
  }

我无法弄清楚这段代码有什么问题。文件上传没有发生。

【问题讨论】:

    标签: javascript jquery ruby-on-rails carrierwave jquery-file-upload


    【解决方案1】:

    你为什么不试试这个 gem remotipart

    【讨论】:

    • 我还没有尝试 remotipart。原因是,即使 remotipart 也使用 iframe Transport jQuery,它已经包含在 jQuery File Upload 插件中。
    • 是的,但想法是它会解决 JS 问题,您只需在表单中添加 remote: true ,然后将其与其他任务一起使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    • 2018-06-01
    相关资源
    最近更新 更多