我想减少我申请表中的路由,以便:
http://myapplication.com/users/peter/questions/how-do-i-create-urls
变成...
http://myapplication.com/peter/how-do-i-create-urls
我有一个用户控制器,希望它是足智多谋的.用户还有一个嵌套资源,名为"问题".
Basic routes file
没有任何URL修剪,路由文件如下所示:
...
resources :users do
resources :questions
end
然而,来自该网站的URL采用
http://myapplication.com/users/peter/questions/how-do-i-create-urls
而不是
http://myapplication.com/peter/how-do-i-create-urls
Partial success
...
resources :users, :path => '' do
resources :questions
end
这起作用并产生:
http://myapplication.com/peter/questions/how-do-i-create-urls
然而,如果我try :
...
resources :users, :path => '' do
resources :questions, :path => ''
end
然后事情开始出问题.
这是正确的方法吗?如果是的话,是否也可以使用嵌套资源?