2
我使用的軌道路由的一員,我想有一些像添加淺資源作爲另一個資源
resources :user
member do
resources :comments, shallow: true
end
end
# To get the following routes
get /users/:id/comments (index)
post /users/:id/comments (create)
get /comments/:id (show)
put /comments/:id (update)
delete /comments/:id (destroy)
然而變淺不工作,我有以下途徑(不提的是,:id
用戶和評論是相互矛盾的)
get /users/:id/comments
post /users/:id/comments
get /users/:id/comments/:id
put /users/:id/comments/:id
delete /users/:id/comments/:id
我知道,平時做的推薦方法是
resources :user
resources :comments, shallow: true
end
# To get the following routes
get /users/:user_id/comments
post /users/:user_id/comments
get /comments/:id
put /comments/:id
delete /comments/:id
但我想要:id
在params
而不是:user_id
淺層路由創建/索引。 This is usually done by using member
你可以離開了:上選項,這將創建不同的是值的資源ID將在 PARAMS提供相同的成員 路線[:photo_id]代替PARAMS [:ID]。
有沒有人知道爲什麼在member
指令內完成淺化後不能正常工作?