REST routes & link_to paths

I've mapped this nested route for a product catalog...

  map.resources :brands do |brand|     brand.resources :product_lines do |product_line|       product_line.resources :products do |product|         product.resources :upcs       end     end   end

And the pretty URLS are working great (when manually typed)... /brands/1/product_lines/5/products/10/upcs/15/edit

My problem is I don't know how to construct those pretty links in my link_to and redirect_to paths...

product_lines_path(:brand_id => params[:id]) # returns: /product_lines?brand_id=4 # desired: /brands/4/product_lines

link_to product_path(@product) # returns: /products/4 # desired: /brands/1/product_lines/5/products/4

Any ideas? Thanks.

Sav wrote:

My problem is I don't know how to construct those pretty links in my link_to and redirect_to paths...

Whenever you are looking into a routing issue, your first step should be:

rake routes

run in your application top level and understand what this is telling you.

product_lines_path(:brand_id => params[:id]) # returns: /product_lines?brand_id=4 # desired: /brands/4/product_lines

brand_product_lines_path 1 or: brand_product_lines_path :brand_id => 1

link_to product_path(@product) # returns: /products/4 # desired: /brands/1/product_lines/5/products/4

brand_product_line_product_path 1, 5, 4 or: brand_product_line_product_path :brand_id => 1,         :product_line_id => 5, :product_id => 4

These URLs are pretty cumbersome. Have a look here for some advise on nested resources:

http://weblog.jamisbuck.org/2007/2/5/nesting-resources