正確的路由我有兩個資源,一個是另一個的嵌套的資源:一個奇異嵌套資源
parent_resource
和child_resource
。
這給了我以下途徑:
somesite.com/parent_resources/14
somesite.com/parent_resources/14/child_resources/1
然而,只有永遠將成爲每個parent_resource
單child_resource
,所以要使用該網站,這是非常混亂的人。我希望child_resource路徑如下所示:
somesite.com/parent_resource/14/child_resource
somesite.com/parent_resource/14/child_resource/edit
etc
要做到這一點的正確方法是什麼?
我的routes.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
但是,我們說明了什麼?
我的航線耙途徑產生:
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
我們可以看到你的routes.rb嗎? –
@KennyBania將其添加到問題中。 – Undistraction
您應該將複數名稱傳遞給'resources'並將一個單數名稱傳遞給'resource'。你將單數傳遞給兩者。 –