Routing Issue


#1

Hi,

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 http://www.example.com/, 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,
since:

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.

Thanks,
Andrew


#2

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 !


#3

Additionaly: when I use browse_path(nil) it renders out just fine…


#4

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;


Cheers

Koz