Rails 3 - Nested Routes "NoMethodError" despite being listed in rake routes
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开发者_如何学Python/:app_id/forms/:id(.:format) {:controller=>"forms", :action=>"show"}
Any help would be greatly appreciated!
Try app_form_path(@app, form)
instead (you need to append _path
to the route name).
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)
精彩评论