【发布时间】:2015-01-09 16:37:03
【问题描述】:
我正在使用 Rails 路由,我想要类似的东西
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
但我希望在浅化路由创建/索引上使用params 中的:id 而不是:user_id。 This is usually done by using member
您可以省略 :on 选项,这将创建相同的成员 除了资源 id 值将在 params[:photo_id] 而不是 params[:id]。
有谁知道为什么在 member 指令内进行浅化处理时无法正常工作?
【问题讨论】:
标签: ruby-on-rails ruby routing