2011-06-05 51 views
2

我試圖做一個簡單的博客與職位控制器路由到根url而不是localhost/posts /:id。軌道路線:除了問題

添加以下到我的路線文件...

match '/:id', :to => 'posts#show', :as => 'post' 

這已經足夠好了。它已經打破了我的搜索路線。

match 'search/:q', :to => 'posts#query', :as => 'search' 

它看起來像rails試圖找到一個與我的搜索查詢ID的職位。有沒有辦法像下面這樣讓路由文件在根url是post id之後假設所有東西EXECPT任何以'search'開頭的東西?

match '/:id', :to => 'posts#show', :as => 'post', :except => 'search' 

回答

5

Rails自上而下解析您的路線並在第一場比賽中停止。我會把你的match '/:id'...線放在你所有其他路線的下面。