【问题标题】:jquery fileupload rails method defaults to put instead of postjquery fileupload rails 方法默认为 put 而不是 post
【发布时间】:2014-01-24 08:35:44
【问题描述】:

我在我的 rails 应用程序中使用 jquery-fileupload-rails gem / BlueImp/jquery-file-upload。

我正在尝试在使用 form_for @transaction 的 /Transactions/:id/edit 页面上上传与我的模型(事务)关联的嵌套资源(文档)。此表单使用 PUT 来更新事务。

现在,我的 .fileupload 元素是页面底部单独 form_for 中的一个 div,并且在 transaction_documents_path 的选项中设置了 url。它使用 POST 来创建交易文档并正常工作。

我想将 .fileupload 元素 div 集成到我的编辑表单中,并且没有两个表单。从文档看来这是可能的。我能够将正确的 transactions_documents_path url 传递给 fileupload,但尝试使用 fileupload 的方法或类型选项指定 POST 方法似乎不会覆盖 form_for 的 PUT 方法。当我开始上传时,我收到一个路由错误(POST 工作正常,PUT 不能。)

关于我如何 POST 而不是 PUT 的任何建议?

.fileupload div:

<div class="container" id="fileupload" data-type="POST" data-url="<%= transaction_documents_path(@transaction)%>">

transactions.js.coffee:

->
  $("#fileupload").fileupload
      method: 'POST'
      type: 'POST'
      progressall: (e, data) ->
        progress = parseInt(data.loaded / data.total * 100, 10)
        $(".progress .bar").css "width", progress + "%"

【问题讨论】:

    标签: ruby-on-rails post methods jquery-file-upload


    【解决方案1】:

    您现在可能已经解决或解决了您的问题,但也许它可以帮助其他人解决同样的问题。您可能正在将外部形式指定为 put 方法(您可以查找名为“_method”的隐藏输入。您可以通过以下方式将其称为帖子:

    <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :post }) do |f| %>
    

    希望对您有所帮助。此外,阅读一些关于 PUT 和 POST 方法的内容也很有趣。有时 PUT 是最适合上传文件的方法。有时... :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-09
      • 2010-10-28
      • 2018-10-16
      • 2014-08-14
      • 2019-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多