Rails路由:将整个路径字符串拉入一个参数

时间:2012-08-24 08:33:32

标签: ruby-on-rails routes

我刚刚在我的rails 2.2.2 app中添加了一个CMS。我想设置它,以便在我的路线的底部,我有一个全能,将整个路径推入一个参数,然后调用cms控制器,然后查找匹配该路径的页面

例如

http://mysite.com/something/about/foo
=> {:controller => "cms", :action => "show", :page => "something/about/foo"}

我无法弄清楚我需要添加哪些选项(如果有的话)来阻止它在斜杠上分割。任何人的想法?记住这是rails 2.谢谢!

1 个答案:

答案 0 :(得分:0)

刚刚在官方的rails api文档(doh)中找到了答案:

4.9 Route Globbing
Route globbing is a way to specify that a particular parameter should be matched
to all  the remaining parts of a route. For example

map.connect 'photo/*other', :controller => 'photos', :action => 'unknown',

就我而言:

map.connect   "/*page", :controller => "cms", :action => "show"

表示

http://mysite.com/something/about/foo
=> {:controller => "cms", :action => "show", :page => ["something", "about", "foo"]}

这很好,因为我可以轻松地加入params [:page]以再次获得完整路径。

感谢阅读:)