2 つのリソースがあり、1 つは別のネストされたリソースです。
parent_resource
とchild_resource
。
これにより、次のルートが得られます。
somesite.com/parent_resources/14
somesite.com/parent_resources/14/child_resources/1
child_resource
ただし、 ごとに1 つしか存在しないparent_resource
ため、サイトを使用している人にとっては非常に混乱します。child_resource パスを次のようにしたいと思います。
somesite.com/parent_resource/14/child_resource
somesite.com/parent_resource/14/child_resource/edit
etc
これを行う正しい方法は何ですか?
私のルート.rb
resources :parent_resources do
resource :child_resource do
end
end
レールガイドからルーティングまで:
A singular resourceful route generates these helpers:
new_geocoder_path returns /geocoder/new
edit_geocoder_path returns /geocoder/edit
geocoder_path returns /geocoder
しかし、ショーはどうですか?
rake ルートによって生成された私のルート:
parent_resource_child_resource POST /parent_resources/:parent_resource_id/child_resource(.:format) child_resources#create
new_parent_resource_child_resource GET /parent_resources/:parent_resource_id/child_resource/new(.:format) child_resources#new
edit_parent_resource_child_resource GET /parent_resources/:parent_resource_id/child_resource/edit(.:format) child_resources#edit
GET /parent_resources/:parent_resource_id/child_resource(.:format) child_resources#show
PUT /parent_resources/:parent_resource_id/child_resource(.:format) child_resources#update
DELETE /parent_resources/:parent_resource_id/child_resource(.:format) child_resources#destroy