Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只需要在我的 rails 应用程序中简化 url。 /nature反而/categories/nature
/nature
/categories/nature
我的routes.rb:
routes.rb
匹配 'categories/:id' => 'categories#show'
match ':id' => 'categories#show'
这将向具有显示操作的类别控制器发出任何“/某事”请求,因此您必须考虑到这一点。
如果我是你,我会这样做:
match ':id' => 'categories#show',:constraints => { :id => /nature|sports|architecture|people|.../ }
这样,您仍然可以根据需要使用 '/something' 路由,只要它们不匹配任何可用类别即可。