post_comment_path(5, 10)?Rails.application.routes.draw do
resources :posts do
resources :comments
end
endIn nested routes, the URL includes the parent resource ID first, then the nested resource ID. So post_comment_path(5, 10) generates /posts/5/comments/10.
Rails nested routes use do...end blocks. Curly braces or hash rockets are not valid here.
/posts/3/comments/7/edit, which controller and action will handle the request?Rails.application.routes.draw do
resources :posts do
resources :comments
end
endThe URL /posts/3/comments/7/edit targets the edit action of the CommentsController because comments are nested inside posts.
post_comment_path(10) raise an error?Rails.application.routes.draw do
resources :posts do
resources :comments
end
endBecause comments are nested inside posts, the helper post_comment_path requires two IDs: the post ID and the comment ID. Passing only one ID causes an argument error.
resources :authors do resources :books end
Each resources generates 7 routes (index, show, new, create, edit, update, destroy). Nesting books inside authors creates 7 routes for authors plus 7 nested routes for books, totaling 14.
