打破浅层嵌套资源(非浅层资源)

时间:2013-10-06 00:04:40

标签: ruby-on-rails ruby routes nested-resources

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

  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

有什么想法吗?

0 个答案:

没有答案