I have a problem with shallow nested resources. My routes have a large tree of invested resources, but one of them should be shallow. Just an example:
resources :days, shallow: true do
resources :meals, shallow: true do
resources :ingredients, shallow: false
resource :recipe, shallow: true
end
end
I would like to have the resources of the days. Inside this shallow food. Inside the food shallow ingredients. Because the ingredients do not have a unique identifier. And another recipe for the resource. The problem is that it shallow: falsedoes not work! This can be found in the Rails manual:
You can also specify the option: shallow in the parent resource, in which case all the embedded resources will be shallow:
So, I get the following routes for the ingredients:
meal_ingredients GET /meals/:meal_id/ingredients(.:format) ingredients
POST /meals/:meal_id/ingredients(.:format) ingredients
new_meal_ingredient GET /meals/:meal_id/ingredients/new(.:format) ingredients
edit_ingredient GET /ingredients/:id/edit(.:format) ingredients
ingredient GET /ingredients/:id(.:format) ingredients
PATCH /ingredients/:id(.:format) ingredients
PUT /ingredients/:id(.:format) ingredients
DELETE /ingredients/:id(.:format) ingredients
But I would like to have something like this:
GET /meals/:meal_id/ingredients
POST /meals/:meal_id/ingredients
GET /meals/:meal_id/ingredients/new
GET /meals/:meal_id/ingredients/:id/edit
GET /meals/:meal_id/ingredients/:id
PATCH /meals/:meal_id/ingredients/:id
PUT /meals/:meal_id/ingredients/:id
DELETE /meals/:meal_id/ingredients/:id
Any ideas?