Rails更改form_for中的提交路由 [英] Rails change routing of submit in form_for

查看:115
本文介绍了Rails更改form_for中的提交路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型 Article和一个模型 Ratings嵌套在文章中。

I have a model 'Article' and a model 'Ratings' nested within articles.

/ articles / 123 / ratings

/articles/123/ratings

我现在想更改f.submit的等级在ratings / _form.html.erb
中,所以按提交后,我的应用程序路由到

I want to change the routing of the f.submit in ratings/_form.html.erb now it is so, that after pressing submit, my application routs to

/ ratings / 111

/ratings/111

但我想将其路由到

/ article / 123

/article/123

如何在form_for f.submit按钮中更改路由。
我在这里找到了类似的东西:

How can I change the routing in a form_for f.submit button. I have found here something like this:

<% form_for :thing, :url => 
 url_for(:action => "update", :id => @thing) do |f| %>

但这不适用于我的rails 3.2。

But this do not work for my rails 3.2. Thanks for your help,

推荐答案

:url-表单提交到的URL。它采用与传递给url_for或link_to相同的字段。特别是,您也可以在此处直接通过命名路线。默认为当前操作。

:url - The URL the form is submitted to. It takes the same fields you pass to url_for or link_to. In particular you may pass here a named route directly as well. Defaults to the current action.

<% form_for :thing, :url => {:action => "update", :id => @thing} do |f| %>

您也可以使用帮助程序将路径名传递给它。因此您也可以执行以下操作

you can also pass it the path_name by using the helper. so you can also do something like

:url => update_article_path(@article)

这篇关于Rails更改form_for中的提交路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆