From cf22ebfa46d8f01517d058f2dada199fd71c7234 Mon Sep 17 00:00:00 2001 From: James Smith Date: Mon, 4 Mar 2024 13:47:33 +0000 Subject: [PATCH] don't redirect back to deleted files or models --- app/controllers/model_files_controller.rb | 7 ++++++- app/controllers/models_controller.rb | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/model_files_controller.rb b/app/controllers/model_files_controller.rb index a7157a4fc..b530bd28c 100644 --- a/app/controllers/model_files_controller.rb +++ b/app/controllers/model_files_controller.rb @@ -51,7 +51,12 @@ def bulk_update def destroy authorize @file @file.delete_from_disk_and_destroy - redirect_back_or_to library_model_path(@library, @model), notice: t(".success") + if URI.parse(request.referer).path == library_model_model_file_path(@library, @model, @file) + # If we're coming from the file page itself, we can't go back there + redirect_to library_model_path(@library, @model), notice: t(".success") + else + redirect_back_or_to library_model_path(@library, @model), notice: t(".success") + end end private diff --git a/app/controllers/models_controller.rb b/app/controllers/models_controller.rb index edb039683..de380f92a 100644 --- a/app/controllers/models_controller.rb +++ b/app/controllers/models_controller.rb @@ -100,7 +100,12 @@ def bulk_update def destroy authorize @model @model.delete_from_disk_and_destroy - redirect_back_or_to library_path(@library), notice: t(".success") + if URI.parse(request.referer).path == library_model_path(@library, @model) + # If we're coming from the model page itself, we can't go back there + redirect_to library_path(@library), notice: t(".success") + else + redirect_back_or_to library_path(@library), notice: t(".success") + end end private