Destruction of small invested resources (shallow resources)

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#index
                     POST   /meals/:meal_id/ingredients(.:format)     ingredients#create
 new_meal_ingredient GET    /meals/:meal_id/ingredients/new(.:format) ingredients#new
     edit_ingredient GET    /ingredients/:id/edit(.:format)           ingredients#edit
          ingredient GET    /ingredients/:id(.:format)                ingredients#show
                     PATCH  /ingredients/:id(.:format)                ingredients#update
                     PUT    /ingredients/:id(.:format)                ingredients#update
                     DELETE /ingredients/:id(.:format)                ingredients#destroy

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?

+4

All Articles