Forum: Ruby on Rails A little confused about routes....

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric N. (Guest)
on 2006-06-04 08:37
I'm currently playing around with various URL patterns and I'm a little
confused about how routes and the _url helpers work.  I've read through
the AWDWR book (1st edition and current 2nd edition beta book) and I'm
still not clear on what's happening.

I've been working with variations of the following route:

  map.competition 'competitions/:short_name/:controller/:action',
              :action=>'show',
              :requirements=>{:short_name => /([A-Z0-9][-A-Za-z0-9+
]*)/}

(One side question, is there a good way to avoid having to allow both
'+' and ' ', in the route regexp -- it seems that the _url helpers
attempt to match before the string is URL-encoded, while the route
dispatch matches before the is URL-decoded?)

1st)
The above route appears to fail on modules:
http://0.0.0.0:3000/competitions/2007+MIT+Open/reg...
leads to a recognition failed error.

http://0.0.0.0:3000/competitions/2007+MIT+Open/reg...
and
http://0.0.0.0:3000/competitions/2007+MIT+Open/register
behave properly.  Is there some aspect of modules that only works when
its the first component of a route?

2nd)
I thought that the _url helpers assume the current controller, however
if I don't explicitly list a controller I end up with a generated URL
like:
http://0.0.0.0:3000/competitions/2007+MIT+Open//start
from a call of
		 competition_url(:action=>'start', :short_name=>@competition)
from a view generated by a URL served by the RegisterController.

I don't really mind having to explicitly add the :controller to my _url
helpers, but I'm wondering why it works some places, but not others.

Thank you,
This topic is locked and can not be replied to.