0

我只需要在我的 rails 应用程序中简化 url。 /nature反而/categories/nature

我的routes.rb

匹配 'categories/:id' => 'categories#show'

4

1 回答 1

1
match ':id' => 'categories#show'

这将向具有显示操作的类别控制器发出任何“/某事”请求,因此您必须考虑到这一点。

如果我是你,我会这样做:

match ':id' => 'categories#show',:constraints => { :id => /nature|sports|architecture|people|.../ }

这样,您仍然可以根据需要使用 '/something' 路由,只要它们不匹配任何可用类别即可。

于 2012-08-11T09:04:51.500 回答