我正在尝试使用帖子控制器路由到根 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 以“搜索”开头的任何内容?
match '/:id', :to => 'posts#show', :as => 'post', :except => 'search'