I have a routes file (Rails 4.0.4 App):
resources :products do
resources :variants, except: :index
end
rake routes gives:
product_variants POST /products/:product_id/variants(.:format) variants#create
new_product_variant GET /products/:product_id/variants/new(.:format) variants#new
edit_product_variant GET /products/:product_id/variants/:id/edit(.:format) variants#edit
product_variant GET /products/:product_id/variants/:id(.:format) variants#show
PATCH /products/:product_id/variants/:id(.:format) variants#update
PUT /products/:product_id/variants/:id(.:format) variants#update
DELETE /products/:product_id/variants/:id(.:format) variants#destroy
So as proposed I'm using
<%= form_for [@product, @variant] do |f| %>
but this generates (note the URL):
<form accept-charset="UTF-8" action="/variants/1" class="edit_variant" id="edit_variant_1" method="post">
And I get (of course) the routing error saying no route matches with PATCH /variants/1
Same strange behaviour when I redirect to in an Api Controller living namespaced under api/:
redirect_to [:api, @product, @variant]
Got me: no route matches with /api/variants/1
So:
- I checked all routes
- I know how to nest resources and namespace them
- I thought I know how to generate the URL's ;-)
Somehow the @products is ignored when generating the urls
Has anyone a clue where to look any further?
@productvariable is not nil.