gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:35:59 25 4
gpt4 key购买 nike

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

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com