From a5f9fc5ca265f963970f0fd72c5f8790e89c83ee Mon Sep 17 00:00:00 2001 From: Mar12358 <120040536+Mar12358@users.noreply.github.com> Date: Tue, 5 Sep 2023 21:54:00 -0300 Subject: [PATCH 1/2] Fix recipe deletion --- app/controllers/recipes_controller.rb | 1 + 1 file changed, 1 insertion(+) 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 From 573c76975d313c9a9e8aeb1b73726f830dad8e30 Mon Sep 17 00:00:00 2001 From: Mar12358 <120040536+Mar12358@users.noreply.github.com> Date: Tue, 5 Sep 2023 21:54:13 -0300 Subject: [PATCH 2/2] Fix Inventory deletion --- app/controllers/inventories_controller.rb | 1 + app/models/inventory.rb | 1 + 2 files changed, 2 insertions(+) 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/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