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.

url_for doesn't work correctly for nested resources

#4682

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.

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

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

Activity

  1. slawosz (at gmail)
    slawosz (at gmail)

    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?

    May 25th, 2010 @ 01:18 PM

  2. Jouko Karvonen
    Jouko Karvonen

    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? :)

    May 25th, 2010 @ 02:17 PM

  3. slawosz (at gmail)
    slawosz (at gmail)

    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.

    May 25th, 2010 @ 02:32 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 2nd, 2011 @ 04:52 PM

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

    February 2nd, 2011 @ 04:52 PM