Forum: Ruby on Rails named_route_url broken in 1.2?

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.
856436f34742e0ddf3bb0e1061742dc1?d=identicon&s=25 Joe Ruby MUDCRAP-CE (joe)
on 2007-05-08 03:55
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 Ruby MUDCRAP-CE
6edd67c92a1dab5eb23fed79f3c18564?d=identicon&s=25 DHH (Guest)
on 2007-05-08 08:07
(Received via mailing list)
> 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.
856436f34742e0ddf3bb0e1061742dc1?d=identicon&s=25 Joe Ruby (Guest)
on 2007-05-08 08:17
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! ;P

Joe Ruby MUDCRAP-CE
856436f34742e0ddf3bb0e1061742dc1?d=identicon&s=25 Joe Ruby (Guest)
on 2007-05-08 08:25
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. ;P I'm used to the rougher
treatment in Zed's forum. ;P

Cheers,
Joe Ruby
This topic is locked and can not be replied to.