Rails 3 - 嵌套路由“NoMethodError”尽管被列入耙子路线
好的,我有一个像这样的嵌套路由:
resources :apps do
resources :forms
end
在我的表单索引中,我有这个块:
<% @forms.each do |form| %>
<tr>
<td><%= form.app_id %></td>
<td><%= form.title %></td>
<td><%= link_to 'Show', app_form(@app,form) %></td>
<td><%= link_to 'Destroy', form, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
页面在 app_form 行上抛出 NoMethodError;但是我认为我正确地传递了应用程序和表单(我也尝试传递@app.id)。调用 rake 路线...甚至会显示路线:
app_form GET /apps/:app_id/forms/:id(.:format) {:controller=>"forms", :action=>"show"}
任何帮助将不胜感激!
Ok guys so I have a nested route like this:
resources :apps do
resources :forms
end
In my form index I have this block:
<% @forms.each do |form| %>
<tr>
<td><%= form.app_id %></td>
<td><%= form.title %></td>
<td><%= link_to 'Show', app_form(@app,form) %></td>
<td><%= link_to 'Destroy', form, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
The page throws a NoMethodError on the app_form line; however I think I am passing in the app and form in correctly (I've also tried to pass in the @app.id). Calling rake routes... the route is even displayed:
app_form GET /apps/:app_id/forms/:id(.:format) {:controller=>"forms", :action=>"show"}
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
app_form_path(@app, form)
(您需要将_path
附加到路由名称)。Try
app_form_path(@app, form)
instead (you need to append_path
to the route name).不仅是嵌套路由,对于您使用的每个路由,您都需要附加 _path 或 _url 以及路由名称。
所以在这里尝试 app_form_path(@app,form) 或 app_form_url(@app,form)
Not only nested routes,For each routes you using, You need to append _path or _url with route name.
So here juz try app_form_path(@app,form) or app_form_url(@app,form)