1

我需要为 Rails 3 中的资源实现一些对 SEO 友好的排序方法。这是我正在考虑为集合做的事情:

/things                  # shows all things
/things/popular          # shows all things ordered by popularity
/things/a-z              # shows all things ordered alphabetically

这对于单个记录:

/thing/name-of-a-thing   # shows ONE thing

单数/复数之间的切换是为了避免事物名称与排序方法名称冲突。

到目前为止,我一直在使用resource :thingswhich uses /thingsfor all actions。我很担心要摆脱默认设置,因为我知道在设置这些默认设置方面已经考虑了很多。所以在我这样做之前,我想我会寻求一些建议,以防这种事情有最佳实践。

那么,这是解决我问题的好方法吗?我是否对未来的任何问题敞开心扉?有没有更好的方法来解决这个问题?

谢谢!

4

1 回答 1

0

您需要通过匹配定义所有路由。

match '/things' => 'Things#index'
match '/things/:order' => 'Things#index'
match '/thing/:id' => 'Things#show'

并在所有匹配路由定义后杀死您的资源、路由或使用它。

于 2010-11-03T07:42:46.270 回答