# Really simple routing question

**URL:** <https://www.ruby-forum.com/t/really-simple-routing-question/108215>\
**Category:** Rails\
**Created:** [June 30, 2007, 5:24am UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215 "2007-06-30T05:24:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![surge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@surge](https://www.ruby-forum.com/u/surge)\
**Post date:** [June 30, 2007, 5:24am UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215/1 "2007-06-30T05:24:50Z")

</div>

I’m just now trying to figure out how rails routing works and to be  
honest, I find it really confusing. Anyway, I just want to create two  
“named” routes to save me some typing. The routes are:

map.home ‘’, :controller =\> ‘main’, :action =\> ‘welcome’  
map.login ‘’, :controller =\> ‘user’, :action =\> ‘login’

What happens is that when I do “redirect\_to login\_url”, the first  
route is invoked. If I comment that first one out, then the second one  
starts working. Aren’t they in different namespaces? Why are they  
conflicting?

---

<div class="post-metadata">

**Author:** ![surge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@surge](https://www.ruby-forum.com/u/surge)\
**Post date:** [June 30, 2007, 1:22pm UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215/2 "2007-06-30T13:22:18Z")

</div>

Your routes are identical in the location that is rendered. The way you  
have  
it now any request that goes to [http://www.yourdomain.com/](http://www.yourdomain.com/) will use the  
map.home route since it is first in the list.

try changing to something like:  
map.home ‘’, :controller =\> ‘main’, :action =\> ‘welcome’  
map.login ‘/login’, :controller =\> ‘user’, :action =\> ‘login’

The first argument is the url that is generated and must be unique. The  
controller and action definitions tell rails where to go when that url  
comes  
in. If you have duplicates then the first item found in the routes file  
will  
be used. Read up on routes and howw they work here (  
[http://wiki.rubyonrails.org/rails/pages/Routes](http://wiki.rubyonrails.org/rails/pages/Routes) ) to get a better  
understanding.

- Adam

---

<div class="post-metadata">

**Author:** ![surge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@surge](https://www.ruby-forum.com/u/surge)\
**Post date:** [June 30, 2007, 3:20pm UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215/3 "2007-06-30T15:20:27Z")

</div>

Adam, thanks for the clarification. It’s definitely something I will  
need to learn in depth. Thanks a lot for the post. By the way, I was  
thinking about how I would go about creating a catchall route and I  
found this on the net:

map.connect ‘\*path’, :controller =\> “some\_controller”, :action =\>  
“some\_action”

That star can’t be a regular expression star, so what is it and do you  
know where I could read about those details?

Thanks once again,  
Sergei

---

<div class="post-metadata">

**Author:** ![surge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@surge](https://www.ruby-forum.com/u/surge)\
**Post date:** [July 1, 2007, 1:30am UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215/4 "2007-07-01T01:30:25Z")

</div>

Funny you should ask about that. I stumbled across something similar and  
use  
the catchall for my 404’s. I didn’t really look into how it works at the  
time.

# catch all…

map.whoops ‘\*anything’, :controller =\> ‘default’, :action =\> ‘whoops’

I did find this though and it may clarify the use of the \*.

> **[\#46 Catch-all Route - RailsCasts](http://railscasts.com/episodes/46-catch-all-route)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

-Adam

---

<div class="post-metadata">

**Author:** ![surge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4da419/32.png) [@surge](https://www.ruby-forum.com/u/surge)\
**Post date:** [July 1, 2007, 2:19am UTC](https://www.ruby-forum.com/t/really-simple-routing-question/108215/5 "2007-07-01T02:19:29Z")

</div>

> [#46 Catch-all Route - RailsCasts](http://railscasts.com/episodes/46)

It’s funny that this is where I found it too! Thanks Adam, I’ll look  
into it.

Sergei
