ネストされたルートを使用しない場合、/profile/1/posts
または/profile/1/posts/1
必要ない場合。ただし、再考することをお勧めします。ネストされたルートはクリーンな RESTful API を実現します
たとえば、すてきなネストされたルートは次のとおりです。
resources :profile, :shallow => true do
resources :posts
end
これらすべての本当に便利なルートを提供します:
profile_posts GET /profile/:profile_id/posts(.:format) posts#index
POST /profile/:profile_id/posts(.:format) posts#create
new_profile_post GET /profile/:profile_id/posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) 投稿#edit
post GET /posts/:id(.:format) posts#show
PUT /posts/:id(.:format) posts#update
/posts/:id(.:format) の削除 #posts#destroy
profile_index GET /profile(.:format) profile#index
POST /profile(.:format) profile#create
new_profile GET /profile/new(.:format) profile#new
edit_profile GET /profile/:id/edit(.:format) profile#edit
profile GET /profile/:id(.:format) profile#show
PUT /profile/:id(.:format) profile#update
削除 /profile/:id(.:format) profile#destroy
このようにして、必要/有用なときにネストされたルートを自由に選択する必要があります。
GET /profile/:profile_id/posts/new(.:format) # create a new post for the given profile_id
GET /profile/:profile_id/posts(.:format) # return all posts for the given profile_id
ネストされたルートが必要ない浅いルートを使用します