问题描述
我在我的应用中设置了以下路由(表单属于站点):
I have the following routing set up in my app (forms belong to a site):
map.resources :sites do |site|
site.resources :forms
end
但是,当我尝试去到使用助手进行表单编辑(或类似)的路径(例如
However, when I try to go to a path for edit (or such) for a form using the helpers (e.g.
edit_site_form_path(form)
或
<%= link_to 'Show', [:site, form] %>
我的网址即将到来换出ID(/ sites / 5 / forms / 1),其中5是表单ID,1是站点ID,来自/ sites / 1页面。
my URLs are coming out with the ID's swapped over ( /sites/5/forms/1 ) where 5 is the form Id, and 1 is the site id. This is from the page /sites/1.
Help(?)
推荐答案
edit_site_form_path
方法必须具有两个参数site_id和form_id,因此在您的示例中,您仅传递了form_id。第一个参数是模型中方法中第一个出现的参数,在这种情况下,它是 site
。第二个参数是form_id。
The edit_site_form_path
method has to have two parameters, the site_id and the form_id. So in your example you are only passing in the form_id. The first parameter is what ever model comes first in the method, in this case it is site
. The second parameter is the form_id.
经过修改的路径方法可能看起来像这样
A revamped path method might look like this
edit_site_form_path(form.site, form)
(假设您有模型表格
其中属于:site
)
这篇关于奇怪的Rails路由行为:在嵌套资源中交换了两个ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!