Forum: Ruby on Rails url_for and routes.rb

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.
454f52683cda0650127b319762bcd529?d=identicon&s=25 Jan Eden (janeden)
on 2007-07-20 15:33
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
map.connect 'firstniftyurl', :controller => 'pages', :action => 'index',
:id => 8

# This one is actually picked by url_for, creating
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
map.connect 'secondniftyurl/:id', :controller => 'pages', :action =>

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?

This topic is locked and can not be replied to.