Forum: Ruby on Rails Routing Issue

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.
Andrew T. (Guest)
on 2006-03-23 21:52

I have these entries in my routes.rb file:

map.connect ':id',
            :controller => 'wiki',
            :action => 'show',
            :id => /^([A-Z]\w*)+$/

map.connect ':controller/:action/:id'

map.connect '',
            :controller => 'wiki',
            :action => 'show',
            :id => 'HomePage'

I only want Rails to use the first route if :id is a camel-case word.
But for some reason, this route catches even when there is no :id
specified in the URL.  So, the first route catches when the URL is
something like, and I receive an error, because
no :id parameter is specified in this case.

I would think that the regex in the first route would prevent this,

irb(main):005:0> nil =~ /^([A-Z]\w*)+$/
=> false
irb(main):006:0> '' =~ /^([A-Z]\w*)+$/
=> nil
irb(main):007:0> 'TestPage' =~ /^([A-Z]\w*)+$/
=> 0

I must be missing something here, but I am not really sure what.  If
anywould could offer any information about this, I would greatly
appreciate it.

François B. (Guest)
on 2006-03-23 22:26
(Received via mailing list)
Hi !

2006/3/23, Andrew T. <removed_email_address@domain.invalid>:
>             :id => 'HomePage'
Move the last entry to the top of the file.  Routes are evaluated in
order, and the first one that matches is the one that will be used.

Hope that helps !
Stijnster (Guest)
on 2009-04-07 08:27
(Received via mailing list)
Additionaly: when I use browse_path(nil) it renders out just fine...
Michael K. (Guest)
on 2009-04-07 08:52
(Received via mailing list)
On Mon, Apr 6, 2009 at 11:24 PM, Stijnster 
<removed_email_address@domain.invalid> wrote:
> Additionaly: when I use browse_path(nil) it renders out just fine...

Trying turning off routing optimisations in environment.rb:

config.action_controller..optimise_named_routes = false

>> When I call the "browse_path" in rails 2.3 it renders;
> >


This topic is locked and can not be replied to.