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 =>
‘index’
I have three questions:
- Why is the first map.connect never used by url_for (why does the
explicit :id parameter interfere)? - Why is the explicit :id parameter acceptable when there is an :id
symbol in the route’s name/label? - Why is the :id symbol removed from the resulting URL because of the
explicit :id parameter?
Cheers,
Jan