Github喜欢Rails中的路由
在rails中使用类似链路径的github
我有与此类似的url:
'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
我不知道为什么因为我已经定义了控制器和动作。
在Rails 3.1中,您可以在路径文件中执行此操作以获得所需内容:
match '/document_managers/:module', :controller => "document_managers", :action => :new_tree, :constraints => {:module => /[ABC]/}