Forum: Ruby on Rails Routes question and defaulting to something

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ramon T. (Guest)
on 2009-02-26 05:09
(Received via mailing list)
Hey everyone!

Is there a way of saying something like this in the routes file (note
that map.connect :controller/:action/:id is my last pattern):
"If the controller you specified doesn't exist, then go to the next

I want this because if users type in, I'd
like the app to render or forward the user to  So, for example, if my
username is ramon, and I type, I will see my profile.

If this is not possible, what's a good way of doing this? :)

Chris K. (Guest)
on 2009-02-26 11:34
(Received via mailing list)
Not sure I understand the behavior you're after completely, but should
able to do this by specifying a named route in your routes file before
default ones.

  map.user_profile   ':username', :controller => 'users', :action =>
  map.connect        ':controller/:action/:id'

This will have the effect, however, of matching any incoming request
only one string.  So you won't be able to have another route like:

  map.user_profile    ':username', :controller => 'users', :action =>
  map.group_profile   ':groupname', :controller => 'groups', :action =>

All requests here meant for either of these would be sent to the
UsersController#show because it appears first in the routes file.

Hope this answers your question.
Ramon T. (Guest)
on 2009-02-27 03:40
(Received via mailing list)
Awesome! That seemed to have worked.  If I type in a /username it
sends me to my profile, if I type in a controller it still defaults to
that controller.

Ramon T.
This topic is locked and can not be replied to.