开发者

Rails routes custom nesting syntax

I would like to map the following legacy url:

/:user_id/comments

comments is a resource, so in an idea world I would use something like:

resources :users, :prefix => nil do
  resources :comments
end

Here I'm using prefix => nil but what I really want is to map just the user id. So instead of /users/:user_id/comments/ I have /:user_id/comments/.

Note that I'm not interested in dec开发者_开发技巧laring a users resource, so if there's something like a namespace that I can use instead all the better.


You can do a match statement to strip out the users folder:

match '/:user_id/:comments' => '/users/:user_id/:comments'


What I ended up using was:

scope ':user_id' do
  resources :comments
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜