2012-08-24 52 views
0

我剛剛添加了CMS到我的Rails 2.2.2應用程序。我想讓它設置好,以便在我的路線的底部,我有一個全面的方法,將整個路徑推入單個參數,然後調用cms控制器,然後查找與該路徑匹配的頁面Rails路由:將整個路徑字符串拖入一個參數

例如

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

我無法弄清楚我需要添加什麼選項(如果有的話),以阻止它在斜槓上分裂。任何想法的人?請記住這是導軌2.謝謝!

回答

0

剛發現官方軌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]再次獲得完整路徑。

感謝您的閱讀:)