Named_route_url broken in 1.2?


#1

Wow, I sure have wasted a lot of time trying to get my named routes to
work in Rails 1.2. Everything worked fine in 1.1. I’m ready to kill
whoever rewrote the routing and broke BC. My routes:

#map.item ‘item/:id’, :controller=>‘items’, :action=>‘show’,
:order=>nil, :requirements => {:id => /\d+/}
map.item ‘item/type/:type/category/:category_id’,
:controller=>‘items’, :action=>‘show’, :category_id => /\d+/, :id =>
/\d+/
map.item ‘item/type/:type/:id’, :controller=>‘items’, :action=>‘show’,
:type=>/\w+/, :id => /\d+/
map.item ‘item/category/:category_id’, :controller=>‘items’,
:action=>‘show’, :category_id => /\d+/, :id => /\d+/
map.item ‘item/:id’, :controller=>‘items’, :action=>‘show’, :id =>
/\d+/
#map.item ‘item/:id/:order’, :controller=>‘items’, :action=>‘show’,
:requirements => {:id => /\d+/}

I either get an error like this:

`raise_named_route_error’: item_url failed to generate from
{:order=>“added”, :id=>“88725”, :action=>“show”, :type=>“pictures”,
:controller=>“items”}, expected: {:action=>“show”, :type=>nil,
:controller=>“items”}, diff: {:order=>“added”, :id=>“88725”, :type=>nil}

or generated URLs look like this:

/item/12345?order=views&type=foo

when they should look like this:

/item/type/foo/12345

WTF?

Joe R. MUDCRAP-CE


#2

Wow, I sure have wasted a lot of time trying to get my named routes to
work in Rails 1.2. Everything worked fine in 1.1. I’m ready to kill
whoever rewrote the routing and broke BC. My routes:

The first rule of free, technical support is that you’re asking for
it, not entitled to it. Thus, you get further by asking nicely. You’re
not asking very nicely, so you shouldn’t be surprised if you’re not
getting a lot of help.

map.item ‘item/type/:type/category/:category_id’,
:controller=>‘items’, :action=>‘show’, :category_id => /\d+/, :id =>
/\d+/
map.item ‘item/type/:type/:id’, :controller=>‘items’, :action=>‘show’,

You’re declaring multiple named routes with the same name. These will
overwrite each other. There can only be one item_url method. Come up
with different names, like map.type_category_item, map.type_item, etc.

WTF?

Attitude is an expensive luxury and you’ve already maxed out all your
good-will credit cards.


#3

DHH wrote:

Wow, I sure have wasted a lot of time trying to get my named routes to
work in Rails 1.2. Everything worked fine in 1.1. I’m ready to kill
whoever rewrote the routing and broke BC. My routes:

The first rule of free, technical support is that you’re asking for
it, not entitled to it. Thus, you get further by asking nicely. You’re
not asking very nicely, so you shouldn’t be surprised if you’re not
getting a lot of help.

map.item ‘item/type/:type/category/:category_id’,
:controller=>‘items’, :action=>‘show’, :category_id => /\d+/, :id =>
/\d+/
map.item ‘item/type/:type/:id’, :controller=>‘items’, :action=>‘show’,

You’re declaring multiple named routes with the same name. These will
overwrite each other. There can only be one item_url method. Come up
with different names, like map.type_category_item, map.type_item, etc.

Wow, really?!? I can’t remember who/what told me it was possible to use
multiple named routes of the same name (perhaps Jarkko I think). Well,
that sucks it’s not possible! Anyhow, thanks for clueing me in!

WTF?

Attitude is an expensive luxury and you’ve already maxed out all your
good-will credit cards.

Hey, I’m MUDCRAP certified! Suck it! :stuck_out_tongue_winking_eye:

Joe R. MUDCRAP-CE


#4

DHH wrote:

map.item ‘item/type/:type/category/:category_id’,
:controller=>‘items’, :action=>‘show’, :category_id => /\d+/, :id =>
/\d+/
map.item ‘item/type/:type/:id’, :controller=>‘items’, :action=>‘show’,

You’re declaring multiple named routes with the same name. These will
overwrite each other. There can only be one item_url method. Come up
with different names, like map.type_category_item, map.type_item, etc.

Seriously, DHH, thanks for pointing that out. You likely saved me
additional hours of banging my head against the screen mistakenly
believing that multiple named routes with the same name were possible
(and why shouldn’t I since they worked before and the docs make no
mention they’re not?). An error should probably result if there’s more
than one named route with the same name.

I was just venting, with tongue in cheek. :stuck_out_tongue_winking_eye: I’m used to the rougher
treatment in Zed’s forum. :stuck_out_tongue_winking_eye:

Cheers,
Joe R.