Rails在form_for中更改提交的路由
我有一个模型’文章’和模型’评级’嵌套在文章中。
/用品/ 123 /评级
我想在rating / _form.html.erb中更改f.submit的路由,现在是这样,按下提交后,我的应用程序路由到
/等级/ 111
但我想把它路由到
/条/ 123
如何在form_for f.submit按钮中更改路由。 我在这里发现了这样的事情:
url_for(:action => "update", :id => @thing) do |f| %>
但这不适用于我的rails 3.2。 谢谢你的帮助,
:url – 表单提交的URL。 它需要传递给url_for或link_to的相同字段。 特别是你也可以直接传递一条命名路线。 默认为当前操作。
<% form_for :thing, :url => {:action => "update", :id => @thing} do |f| %>
您也可以使用帮助程序将其传递给path_name。 所以你也可以这样做
:url => update_article_path(@article)
尝试form_for (:thing, url:{:controller=>'thing', :action=>'update'}, html:{method:'put'})
。