diff --git a/app/controllers/inventories_controller.rb b/app/controllers/inventories_controller.rb index c3ce51d..d96561c 100644 --- a/app/controllers/inventories_controller.rb +++ b/app/controllers/inventories_controller.rb @@ -25,6 +25,7 @@ def new def destroy @inventory = Inventory.find(params[:id]) + @inventory.inventory_foods.destroy_all @inventory.destroy redirect_back_or_to root_path end diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 09fbfeb..e7581c9 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -19,6 +19,7 @@ def new; end def destroy @recipe = Recipe.find(params[:id]) + @recipe.recipe_foods.destroy_all @recipe.destroy redirect_to recipes_path end diff --git a/app/models/inventory.rb b/app/models/inventory.rb index 808aea1..0e3013f 100644 --- a/app/models/inventory.rb +++ b/app/models/inventory.rb @@ -1,3 +1,4 @@ class Inventory < ApplicationRecord belongs_to :user + has_many :inventory_foods end