This project is archived and is in readonly mode.

#3394 ✓stale
iGEL

polymorphic_url fails to generate routes with :path_prefix with a variable

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

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})

Comments and changes to this ticket

  • iGEL

    iGEL October 20th, 2009 @ 08:09 PM

    • 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.

  • iGEL
  • François Beausoleil

    François Beausoleil November 5th, 2009 @ 03:40 PM

    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.

  • François Beausoleil
  • iGEL

    iGEL January 16th, 2010 @ 01:58 PM

    • 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.

  • iGEL

    iGEL January 16th, 2010 @ 02:59 PM

    • 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

  • Rizwan Reza

    Rizwan Reza February 12th, 2010 @ 12:46 PM

    • 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
  • François Beausoleil

    François Beausoleil May 24th, 2010 @ 04:04 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:52 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:52 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages