【发布时间】:2011-08-23 13:14:24
【问题描述】:
在 Rails 中使用类似 github 的链式路由
我有类似这样的网址:
'localhost:3000/document_managers/[:module_name]'
'localhost:3000/document_managers/[:module_name]/1/2/3/.' # can be any level deep
这是他们的路线定义:
map.connect '/document_managers/:module',
:controller => "document_managers",
:action => :new_tree,
:module => ["A","B","C"]
map.connect '/docuemnt_managers/:module/*path',
:controller => "document_managers",
:action => "new_tree",
:module => ["A","B","C"]
问题来了:
-
模块名称值不能是任何东西,除了来自 上面给出的数组,即(“A”,“B”,“C”),在任何时候,URL 都必须类似于
localhost:3000/document_managers/A/1或localhost:3000/document_managers/B/221/1或localhost:3000/document_managers/C/121/1但事实并非如此
localhost:3000/document_managers/D/121/1被视为有效 url 并且模块设置为 D,即使“D”不在列出的数组中 以上 我希望 URL
localhost:3000/document_managers/A如果额外参数不是,也重定向到相同的操作,即 new_tree 在 URL 中提供包含额外参数localhost:3000/document_managers/C/121/1然后 URL 被重定向 适合所需的控制器和操作,但如果仅 URL 包含路径,直到 Rails 的模块名称返回routes ActionController::UnknownAction我不知道为什么,因为我已经 定义了控制器和动作。
【问题讨论】:
-
答案可能是不可接受的,但评论给出的答案将有助于其他用户理解他的问题并相应地调整他们的答案。
-
对不起,我不知道这样的事情我会确保我会接受所有的答案,但看看我的问题列表,我还没有找到人回答我的问题,所以接受什么
标签: ruby-on-rails ruby url-routing