views:

27

answers:

2

I am having trouble with paths in ruby on rails

My Routes:

    map.resources :companies do |company|
  company.resources :customers do |customer|
   customer.resources :jobs 
  end
  end

Currently I am creating the paths by hand:

<td><%= link_to 'Show', "/companies/#{params[:company_id]}/users/#{user.id}" %></td>
<td><%= link_to 'Edit', "/companies/#{params[:company_id]}/users/#{user.id}/edit" %></td>

For some reason I cant figure out how to get new_company_user to work I keep getting errors.

The routes are all there I just need help with dynamically creating them by using the API

A: 

You can run rake routes from the command line and it will print a list of all routes generated from routes.rb, including named routes, the URL and HTTP request type that trigger them, and which controller action they run.

Jimmy Cuadra
I did the rake and could see the route and could even write it out by hand but I couldnt figure out how to API. I figured out my problem was that I didnt add the right params in the path edit_company_user_path(params[:company_id],user) is working. Thanks for your help guys.
dweebsonduty
+3  A: 

If you'd like to use new_company_user then you'd want something like this:

map.resources :companies do |company|
  company.resources :users do |user|
    user.resources :jobs 
  end
end
Andy Gaskell
OMG, thanks. I am blind.
dweebsonduty
No problem, sometimes all it takes is an extra set of eyes :)
Andy Gaskell