form_tag url_for with:方法“delete”,id和:remote =>真正

时间:2011-12-05 21:24:47

标签: ruby-on-rails-3 form-helpers

我有以下form_tag工作:

<%= form_tag url_for(:controller => "profiles", :action => "remove_academic", :method => :delete), :id => "remove_major_goal", :remote => true do %>

但是,生成的HTML显示:method =&gt; &#34;删除&#34;不工作。所以我在form_tag上找到了一些answers并尝试了这个:

<%= form_tag url_for({ :controller => "profiles", :action => "remove_academic", :method => "delete" }, { :id => "remove_major_goal", :remote => true }) do %>

然而,这会引发错误。我做错了什么?

1 个答案:

答案 0 :(得分:2)

DELETE不是HTML表单元素的method属性的有效值。您可能最好在表单中插入<input type="hidden" name="method" value="delete" />(或使用帮助程序方法)。

更新

尝试以下方法之一:

form_for url_for(:controller => "", :action => ""), :method => "delete", …

form_for { :controller => "", :action => "" }, { :method => "delete", … }

第二种形式的第二组括号可能是不必要的。同样,第一种形式可能需要它们。