开发者

Rails routing :except question

开发者 https://www.devze.com 2023-03-10 19:20 出处:网络
I\'m trying to make a simple blog with a posts controller route to the root url rather than localho开发者_StackOverflow社区st/posts/:id.

I'm trying to make a simple blog with a posts controller route to the root url rather than localho开发者_StackOverflow社区st/posts/:id.

I added the following to my routes file...

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

Which worked well enough. It has since broken my search route.

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

It looks like rails is trying to find a post with the id of my search query. Is there a way of doing something like the following to get the routes file to assume everything after the root url is a post id EXECPT anything starting with 'search'?

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


Rails parses your routes from the top down and stops at the first match. I would put your match '/:id'... line below all your other routes.

0

精彩评论

暂无评论...
验证码 换一张
取 消