ルーティングをネストしている時のprefix

routes.rb
#--- 略 ---
 
resources :posts do
    resources :comments
end

 

 rails routes
prefix HTTPメソッド パス アクション
post_comments GET /posts/:post_id/comments(.:format) comments#index
  POST /posts/:post_id/comments(.:format) comments#create
new_post_comment GET /posts/:post_id/comments/new(.:format) comments#new
edit_post_comment GET /posts/:post_id/comments/:id/edit(.:format) comments#edit
post_comment GET /posts/:post_id/comments/:id(.:format) comments#show
  PATCH /posts/:post_id/comments/:id(.:format) comments#update
  DELETE /posts/:post_id/comments/:id(.:format) comments#destroy

 

<例>showへのページ移動時

パスは「/posts/:post_id/comments/:id(.:format)」

IDの指定が2箇所あるので、引数が2つ必要(どの投稿IDか、どのコメントIDか)

post_comment_path(comment.post.id, comment.id)