javascript - 在 Bootstrap 中添加后,Rails 表单会 POST 而不是 DELETE 吗?

标签 javascript jquery ruby-on-rails ruby twitter-bootstrap

我最近刚刚添加了使用以下代码行对表列进行排序的功能:

<table data-toggle="table" class= "table">
.  
.
.
<th data-sortable = "true"> Some header column </th>
.
.
<%= form_tag(sccm_destroy_multiple, method: :delete) %>
 .
 .
 .
 <%end%>

因此,在我添加 data-toggle="table"data-sortable="true" 行之后(在添加这些行之前工作正常),我的表单开始发出 POST 请求而不是 DELETE,关于如何解决此问题有什么想法吗?

另外:

application.js:

//= 需要 Bootstrap 表

最佳答案

您可以发布从页面生成的 HTML 表单吗?

根据the docs ,您应该有以下隐藏字段。你看到那个字段了吗?

<form accept-charset="UTF-8" action="/sccm_destroy_multiple" method="post">
  <input name="_method" type="hidden" value="delete" />

The Rails framework encourages RESTful design of your applications, which means you'll be making a lot of "PATCH" and "DELETE" requests (besides "GET" and "POST"). However, most browsers don't support methods other than "GET" and "POST" when it comes to submitting forms.

Rails works around this issue by emulating other methods over POST with a hidden input named "_method", which is set to reflect the desired method:

关于javascript - 在 Bootstrap 中添加后,Rails 表单会 POST 而不是 DELETE 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35611442/

相关文章:

javascript - 如何使用react-router 2作为expressjs的服务器端路由?

javascript - $ ("#ELEMENT_ID") vs $ ('div[id="ELEMENT_ID"]')

javascript - 如何更改脚本以适合下拉列表?

ruby-on-rails - 设计 View 未在 Rails 中设置样式

javascript - Rails 简单形式数组文本输入

javascript - Coffeescript 将文本文件的内容加载到字符串变量中

javascript - 在 jQuery UI 对话框中的表单中调用 Parsley.js 时,错误消息未出现?

javascript - 错误添加负数jquery

jQuery .html() 函数

ruby-on-rails - 如何修复 capistrano 部署? git 退出状态 : 1