SEO-friendly URL design for filtering a resource in Rails 3

650 views Asked by At

I need to implement some SEO-friendly sort methods for a resource in Rails 3. This is what I'm considering doing for collections:

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

And this for single records:

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

The switching between singular/plural is to avoid thing-names colliding with sort-method-names.

Until now I have been using resource :things which uses /things for all actions. I'm apprehensive to break away from the defaults since I know a lot of thought has gone into making those defaults. So before I do, I thought I'd seek some advice in case there's a best practice for this kind of thing.

So, is this a good way to solve my problem? Am I opening myself up to any problems down the road? Are there better ways to go about this?

Thanks!

1

There are 1 answers

1
shingara On

You need define all route by match.

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

and kill your resources, route or use it after all match route define.