# Routes.rb

**URL:** <https://www.ruby-forum.com/t/routes-rb/144040>\
**Category:** Rails\
**Created:** [July 24, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/routes-rb/144040 "2008-07-24T21:18:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@justinmc](https://www.ruby-forum.com/u/justinmc)\
**Post date:** [July 24, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/routes-rb/144040/1 "2008-07-24T21:18:14Z")

</div>

I feel like I’m doing something stupid, because I haven’t been able to  
fix this.

I have this in my routes.rb file:

map.resources :networks, :has\_many =\> :nodes  
map.resources :auth  
map.connect ‘users/login’, :controller =\> ‘users’, :action =\>  
‘login’  
map.resources :users  
map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’

I’m trying to generate an url that goest to localhost:3000/users/  
login … but no matter what I do, that url always tries to work  
through the “show” action as opposed to the “login” action I have in  
the users controller.

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![justinmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@justinmc](https://www.ruby-forum.com/u/justinmc)\
**Post date:** [July 25, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/routes-rb/144040/2 "2008-07-25T14:22:37Z")

</div>

hi justin,  
my first guess is that are not reloading the routing table after  
making the change. Remember to restart the server for new routes to  
take effect. When I check in my code, your route just works fine.

dirk.

---

<div class="post-metadata">

**Author:** ![justinmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@justinmc](https://www.ruby-forum.com/u/justinmc)\
**Post date:** [July 25, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/routes-rb/144040/3 "2008-07-25T14:25:33Z")

</div>

Add the line

map.connect ‘users/login’, :controller =\> ‘users’, :action =\> ‘login’

after

map.resources :users

in your routes.rb

---

<div class="post-metadata">

**Author:** ![justinmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@justinmc](https://www.ruby-forum.com/u/justinmc)\
**Post date:** [July 25, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/routes-rb/144040/4 "2008-07-25T14:33:11Z")

</div>

Why should that work? Routes are consulted in the order they are  
defined in routes.rb. So if you have  
map.resources :users  
before  
map.connect ‘/users/login’  
it will catch the ‘/users/:id’ declaration of the RESTful resource  
routes and always get justin to the show action before it even reaches  
the ‘/users/login’ declaration.

dirk.

---

<div class="post-metadata">

**Author:** ![justinmc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b77776/32.png) [@justinmc](https://www.ruby-forum.com/u/justinmc)\
**Post date:** [July 25, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/routes-rb/144040/5 "2008-07-25T15:13:06Z")

</div>

thats right. the order is from top to bottom. It was my mistake.
