# Url\_for and routes.rb

**URL:** <https://www.ruby-forum.com/t/url-for-and-routes-rb/109942>\
**Category:** Rails\
**Created:** [July 20, 2007, 3:33pm UTC](https://www.ruby-forum.com/t/url-for-and-routes-rb/109942 "2007-07-20T15:33:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![janeden](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@janeden](https://www.ruby-forum.com/u/janeden)\
**Post date:** [July 20, 2007, 3:33pm UTC](https://www.ruby-forum.com/t/url-for-and-routes-rb/109942/1 "2007-07-20T15:33:46Z")

</div>

I am still struggling with url\_for and routing. This is what I do:

\<%= url\_for :controller =\> ‘pages’, :action =\> ‘index’, :id =\> 8 %\>

# This one is never used by url\_for, although it works fine when

requesting [http://myhost/firstniftyurl](http://myhost/firstniftyurl)  
map.connect ‘firstniftyurl’, :controller =\> ‘pages’, :action =\> ‘index’,  
:id =\> 8

# This one is actually picked by url\_for, creating

[http://myhost/myniftyurl](http://myhost/myniftyurl) (no :id in the URL)  
map.connect ‘myniftyurl/:id’, :controller =\> ‘pages’, :action =\>  
‘index’, :id =\> 8

# This creates the expected [http://myhost/secondniftyurl/8](http://myhost/secondniftyurl/8)

map.connect ‘secondniftyurl/:id’, :controller =\> ‘pages’, :action =\>  
‘index’

I have three questions:

1. Why is the first map.connect never used by url\_for (why does the  
explicit :id parameter interfere)?
2. Why is the explicit :id parameter acceptable when there is an :id  
symbol in the route’s name/label?
3. Why is the :id symbol removed from the resulting URL because of the  
explicit :id parameter?

Cheers,  
Jan
