4

我对浅层嵌套资源有疑问。我的路线有一棵嵌套资源的大树,但其中一个必须是非浅层的。简单的例子:

  resources :days, shallow: true do
    resources :meals, shallow: true do
      resources :ingredients, shallow: false
      resource :recipe, shallow: true
    end
  end

我想有天资源。它里面的浅餐资源。一餐非浅食材资源。因为成分没有唯一的 id。而且配方资源。问题是shallow: false不工作!这可以在 Rails 指南中找到:

您还可以在父资源中指定 :shallow 选项,在这种情况下,所有嵌套资源都将是浅的:

所以我得到了这样的配料路线:

    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

但我想要这样的东西:

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

有任何想法吗?

4

0 回答 0