I have a basic app in Rails 3.2 – two main controllers: users and articles.
The basic routing is like web.com/users/john and web.com/articles/articles-name.
With the match rule I can make the URLs above shorter:
match "u/:permalink" => "users#my_action_name"
match "a/:permalink" => "articles#my_action_name"
allow me to do
web.com/u/john and web.com/a/articles-name
But in the best way, I would like to make the URL yet shorter and more readable, like this (this way use for instance Twitter – twitter.com/username)
web.com/john and web.com/articles-name
But I can’t imagine, how to realize this way of routing. In the app are used also another controllers, like for example HomeController with actions index, about, contact.
Take a look at the “Route Globbing” section of the official Rails guides. You need to add something like
at the end of your
config/routes.rbfile. This will catch all request that found no matchers in your routes file so far. Then your controller has to identify what to do with the request.