如何使用不同的HTTP方法将表单提交到自定义URL?

时间:2021-10-29 18:58:40

I'm using simple_form gem to build my forms, and I'd like to submit a form to "/messages/delete_all" with the DELETE method. How can I do that with simple_form?

我正在使用simple_form gem来构建我的表单,并且我想使用DELETE方法向“/ messages / delete_all”提交表单。我怎么能用simple_form做到这一点?

Here is what I have so far:

这是我到目前为止:

=simple_form_for :messages, :url=>{:action=>"delete_all"} do |f|    
   =f.button :submit, "Delete"

This doesn't seem to work, though. It submits to "/messages/delete_all" with POST.

但这似乎不起作用。它使用POST提交“/ messages / delete_all”。

2 个解决方案

#1


-2  

I'd imagine simple form is rendering just a <form> element with a method of DELETE. If that is the case, DELETE and PUT are not supported in HTML5:

我认为简单的表单只是使用DELETE方法呈现

元素。如果是这种情况,HTML5中不支持DELETE和PUT:

http://www.w3.org/TR/2010/WD-html5-diff-20101019/
http://dev.w3.org/html5/spec/Overview.html#attr-fs-method

I thought that PUT and DELETE were going to be supported in HTML5 forms, but it looks like they no longer will be :(

我认为PUT和DELETE将在HTML5表单中得到支持,但看起来它们将不再是:(

#2


1  

simple_form_for :messages, :method => :delete, ...

#1


-2  

I'd imagine simple form is rendering just a <form> element with a method of DELETE. If that is the case, DELETE and PUT are not supported in HTML5:

我认为简单的表单只是使用DELETE方法呈现

元素。如果是这种情况,HTML5中不支持DELETE和PUT:

http://www.w3.org/TR/2010/WD-html5-diff-20101019/
http://dev.w3.org/html5/spec/Overview.html#attr-fs-method

I thought that PUT and DELETE were going to be supported in HTML5 forms, but it looks like they no longer will be :(

我认为PUT和DELETE将在HTML5表单中得到支持,但看起来它们将不再是:(

#2


1  

simple_form_for :messages, :method => :delete, ...