This project is archived and is in readonly mode.

#4682 ✓stale
Jouko Karvonen

url_for doesn't work correctly for nested resources

Reported by Jouko Karvonen | May 24th, 2010 @ 05:44 PM

If I create 2 scaffolds, for example Shop and Product and create nested routes so that

resources :shop do
  resources :product
end

Then, in the view, shop_products_url(@shop, @product) produces /shops/1/products/1 correctly,
but in the controller, shop_products_url(@shop, @product) produces /shops/1/products.1
(also _path is affected).

As for testing:

post :create, :product => @product.attributes, :shop_id => @shop.id
assert_redirected_to shop_products_path(@shop, assigns(:product))       # Success
assert_redirected_to "shops/#{@shop.id}/products/#{@product.id}"        # Fail <shops/1/products.1>

I'm able to reproduce this with 1.8.7, 1.9.1, 1.9.2-head and rails3 beta3 and rails3 edge.

Comments and changes to this ticket

  • slawosz (at gmail)

    slawosz (at gmail) May 25th, 2010 @ 01:18 PM

    For me,

      shop_products_url(@shop, @product)
    
    produces /shops/1/products.1, becouse you use 'products' in helper name - so it's provides link to product collection.
    Could you show controller you are testing?
  • Jouko Karvonen

    Jouko Karvonen May 25th, 2010 @ 02:17 PM

    Aah, I see. So you're saying it should be singular.
    That seems to do the expected thing.

    This might not be a real bug then, but it sure got me wondering what's going on wrong for some hours...

    Is that "." a correct behavior then? And any explanation? :)

  • slawosz (at gmail)

    slawosz (at gmail) May 25th, 2010 @ 02:32 PM

    It looks like, that second argument in this example

    shop_products_url(@shop, @product)
    

    it is simply mime format. But I will check it exacly later.

  • Santiago Pastorino

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

    • State changed from “new” to “open”

    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>

Tags

Pages