Vanity URLs for Multiple Controllers in Rails
There is no denying that good URL design is crucial for a successful web application. It’s the first thing visitors see of your site and if you did an alright job it’s one of the things that they’ll be able to recollect.
In my current project I wanted to route top level sections to different controllers, similar to Quora’s URL structure.
'http://www.site.com/Nikola-Tesla' => UsersController 'http://www.site.com/Alternating-Current' => TopicsController
The Ruby on Rails router doesn’t provide this functionality out the box but with some small changes we can make this work.
- Clean URL’s without numeric id
- Top level slugs should be able to point to several controllers
- Slug name can be changed, old slug redirects (301) to new one
- Letter case in slugs should be insensitive, redirect to original