How on earth do I link up to a parent resource? My
Companies have many
In my orders view, I have listed the associated company with
However, when I try and use link_to, it links only to the order:
<%= link_to @order.company.name, company_path %>
In my routes, I have this:
resources :companies do
resources :orders do
What's the fix and where can I read more about it?
<%= link_to @order.company.name, company_path(@order.company) %>
You have to pass something to
company_path so that it knows which
Company to get the path for. That is distinct form
companies_path which returns the path for all the companies.
I guess you have a model orders and a model companies. so companies has_many orders. If you setup this with the usual way your records are all have id as identifier. In this case company.id is the record id if you want to make a link back to the company page.