I have a rails application with nested resources, for example:
resources :product do
resources :sales
end
Where Sale belongs_to Product, and a copy Salecannot exist without a product.
I can use link_to+ @productto directly link to the product:
<%= link_to @product.name, @product %>
It creates
<a href="/products/3">Strawberry Jam</a>
If I want to do something like this for sale, I cannot use it only @sale. I have to use the product. This will not work:
<%= link_to @sale.date, @sale %>
I should use something like this:
<%= link_to @sale.date, [@sale.product, @sale] %>
The first case will not work, because it is sale_pathnot defined (only product_sale_paththere is).
My question is: can I add something to the Sale model so that link_to(or url_for) automatically adds the "parent" (the product in this case) when creating the URL?
url_for, , monkeypatching HelperMethodBuilder.url.handle_model_call, , .