Given a request to a URL like this:
/products/42
product_path(@product) will generate the path '/products/42'
Given a request to a URL like this:
/brands/16/products/42
product_path(@product) will generate the path '/brands/42/products', which is unlikely to be what was wanted.
The 'classic' behaviour of url_for fills missing values from the request parameters, so given the same URL product_path(:id => @product) would generate the path '/brands/16/products/42'; it would be more consistent and more useful for product_path(@product) to work in the same way.
The current behaviour is due to the arguments being paired with dynamic segments in the path from left to right. It would be better to pair the arguments from right to left instead:
| :brand_id | :id
|
| current | @product.id | nil
|
| suggested | nil | @product.id
|
or more generally, given the URL /as/:a_id/bs/:b_id/cs/:c_id/ds/:id and the call to d_path(@c, @d):
| :a_id | :b_id | :c_id | :id
|
| current | @c.id | @d.id | nil | nil
|
| suggested | nil | nil | @c.id | @d.id
|