Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

polymorphic_url fails to generate routes with :path_prefix with a variable

#3394

polymorphic_url raises an error, if the given resource has a path_prefix, which contains a variable. For example, if this resource is defined:

map.resource :articles, :path_prefix => ":locale"

The problem is, that polymorphic_url gives an Array to the route:

link_to @article.name, @article => articles_url([1]) # /:locale/articles/:id

This would fill in the 1 into the locale, leaving the article id unsatisfied. I created a patch for Rails 3 (I will provide a patch for Rails 2.3 soon), which changes this behavior, so a Hash is given instead:

articles_url({:id => 1}) # /:locale/articles/:id

If the user provided the locale to polymorphic_route or defined it in default_url_options, that route can be generated. For nested routes, it will set the keys correctly (e.g. {:author_id => 3, :id => 7})

Reported by iGEL · October 19th, 2009 @ 11:36 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. iGEL
    iGEL
    • Tag changed from 2-3-stable, 3.0, action_pack, patch, polymorphic_path to 2-3-stable, 2.3.5, 3.0, action_pack, patch, polymorphic_path

    Here my patch for Rails 2-3-stable.

    Unfortunately my patch for Rails 3.0 doesn't cleanly apply to the master anymore because of this commit: a74022ecd3e078f55ed6049a96565119dc540ff5 I will provide a new patch tomorrow or something.

    October 20th, 2009 @ 08:09 PM

  2. iGEL
  3. François Beausoleil
    François Beausoleil

    I used the rails2-3 patch on our code. It looks good and does what we need it to do. We would like to see this included in 2.3.5. The code isn't in production yet, but staging looks good.

    November 5th, 2009 @ 03:40 PM

  4. François Beausoleil
  5. iGEL
    iGEL
    • Tag changed from 2-3-stable, 2.3.5, 3.0, action_pack, patch, polymorphic_path to 2-3-stable, 2.3.6, 3.0, action_pack, bugmash, bugmash-patch, patch, polymorphic_path

    I've updated the patch for rails 2-3-stable. Will do the same for the rails 3 now.

    January 16th, 2010 @ 01:58 PM

  6. iGEL
    iGEL
    • Tag changed from 2-3-stable, 2.3.6, 3.0, action_pack, bugmash, bugmash-patch, patch, polymorphic_path to 2-3-stable, 2.3.6, action_pack, bugmash, bugmash-patch, patch, polymorphic_path

    Looks like rails 3 doesn't need a patch anymore, because of this commit: 427a7385eb9b784ad4372bf607217b0b7b2ca543

    January 16th, 2010 @ 02:59 PM

  7. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2-3-stable, 2.3.6, action_pack, bugmash, bugmash-patch, patch, polymorphic_path to 2-3-stable, 2.3.6, action_pack, bugmash-patch, patch, polymorphic_path

    February 12th, 2010 @ 12:46 PM

  8. François Beausoleil
    François Beausoleil
    • Tag changed from 2-3-stable, 2.3.6, action_pack, bugmash-patch, patch, polymorphic_path to 2-3-stable, action_pack, bugmash-patch, patch, polymorphic_path

    This patch is in production since December 2009 for us. We've had great success. Would like to see this applied on 2-3-stable.

    May 24th, 2010 @ 04:04 PM

  9. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:52 PM

  10. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:52 PM