# Routes question and defaulting to something

**URL:** <https://www.ruby-forum.com/t/routes-question-and-defaulting-to-something/161388>\
**Category:** Rails\
**Created:** [February 26, 2009, 4:09am UTC](https://www.ruby-forum.com/t/routes-question-and-defaulting-to-something/161388 "2009-02-26T04:09:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 26, 2009, 4:09am UTC](https://www.ruby-forum.com/t/routes-question-and-defaulting-to-something/161388/1 "2009-02-26T04:09:43Z")

</div>

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  
pattern”

I want this because if users type in [domain.com/noncontrollername](http://domain.com/noncontrollername), I’d  
like the app to render or forward the user to  
[domain.com/profiles/noncontrollername](http://domain.com/profiles/noncontrollername). So, for example, if my  
username is ramon, and I type [domain.com/ramon](http://domain.com/ramon), I will see my profile.

If this is not possible, what’s a good way of doing this? 🙂

Thanks!  
Ramon

---

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 26, 2009, 10:34am UTC](https://www.ruby-forum.com/t/routes-question-and-defaulting-to-something/161388/2 "2009-02-26T10:34:55Z")

</div>

Not sure I understand the behavior you’re after completely, but should  
be  
able to do this by specifying a named route in your routes file before  
the  
default ones.

Ex:  
map.user\_profile ‘:username’, :controller =\> ‘users’, :action =\>  
‘show’  
map.connect ‘:controller/:action/:id’  
…

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

map.user\_profile ‘:username’, :controller =\> ‘users’, :action =\>  
‘show’  
map.group\_profile ‘:groupname’, :controller =\> ‘groups’, :action =\>  
‘show’

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.

---

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [February 27, 2009, 2:40am UTC](https://www.ruby-forum.com/t/routes-question-and-defaulting-to-something/161388/3 "2009-02-27T02:40:35Z")

</div>

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.

Thanks!  
Ramon T.
