From 02d5802988a4b9d6128f9412d6c6dbb7f1e17277 Mon Sep 17 00:00:00 2001 From: Mae Beale Date: Fri, 23 Oct 2026 11:47:44 -0400 Subject: [PATCH] Fix 404 when removing a staff tagging from its edit page The Remove link sits inside a turbo: false form, so Turbo ignored its turbo_method: :delete and the browser sent a plain GET to a route with no show action. Re-enable Turbo on the link, and send the user back to the page they came from after removal, matching the eyebrow. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/controllers/staff_taggings_controller.rb | 2 +- app/views/staff_taggings/edit.html.erb | 6 ++++-- spec/requests/staff_taggings_spec.rb | 21 ++++++++++++++++++-- spec/system/staff_tagging_removal_spec.rb | 18 +++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 spec/system/staff_tagging_removal_spec.rb diff --git a/app/controllers/staff_taggings_controller.rb b/app/controllers/staff_taggings_controller.rb index ee396df222..076ab89e76 100644 --- a/app/controllers/staff_taggings_controller.rb +++ b/app/controllers/staff_taggings_controller.rb @@ -66,7 +66,7 @@ def update def destroy authorize! @staff_tagging @staff_tagging.destroy - redirect_to staff_taggings_path, notice: "Staff tagging was successfully removed.", status: :see_other + redirect_to staff_tagging_return_path, notice: "Staff tagging was successfully removed.", status: :see_other end def toggle_marked diff --git a/app/views/staff_taggings/edit.html.erb b/app/views/staff_taggings/edit.html.erb index bf8b488344..fe4dc187e3 100644 --- a/app/views/staff_taggings/edit.html.erb +++ b/app/views/staff_taggings/edit.html.erb @@ -54,8 +54,10 @@
<% if allowed_to?(:destroy?, @staff_tagging) %> - <%= link_to "Remove tagging", staff_tagging_path(@staff_tagging), class: button_classes(:danger_outline), - data: { turbo_method: :delete, turbo_confirm: "Remove this tag from #{taggable&.name}?" } %> + <%= link_to "Remove tagging", + staff_tagging_path(@staff_tagging, return_to: params[:return_to].presence, origin_id: params[:origin_id].presence, admin: params[:admin].presence), + class: button_classes(:danger_outline), + data: { turbo: true, turbo_method: :delete, turbo_confirm: "Remove this tag from #{taggable&.name}?" } %> <% end %> <%= link_to "Cancel", back_path, class: button_classes(:secondary_outline) %> <%= f.button :submit, "Save changes", class: button_classes(:primary) %> diff --git a/spec/requests/staff_taggings_spec.rb b/spec/requests/staff_taggings_spec.rb index 27b6807014..386ff2d556 100644 --- a/spec/requests/staff_taggings_spec.rb +++ b/spec/requests/staff_taggings_spec.rb @@ -357,13 +357,30 @@ describe "DELETE /staff_taggings/:id" do before { sign_in admin } - it "removes a tagging" do + it "removes a tagging and returns to the staff taggings list" do tagging = create(:staff_tagging) expect { - delete staff_tagging_path(tagging) + delete staff_tagging_path(tagging, return_to: "staff_taggings") }.to change(StaffTagging, :count).by(-1) expect(response).to redirect_to(staff_taggings_path) end + + it "returns to the staff tag it was removed from" do + tagging = create(:staff_tagging) + + delete staff_tagging_path(tagging, return_to: "staff_tag") + + expect(response).to redirect_to(staff_tag_path(tagging.staff_tag)) + end + + it "returns to the person's edit page by default" do + person = create(:person) + tagging = create(:staff_tagging, staff_taggable: person) + + delete staff_tagging_path(tagging) + + expect(response).to redirect_to(edit_person_path(person, anchor: "staff_tagging_#{tagging.id}")) + end end end diff --git a/spec/system/staff_tagging_removal_spec.rb b/spec/system/staff_tagging_removal_spec.rb new file mode 100644 index 0000000000..ef92160f24 --- /dev/null +++ b/spec/system/staff_tagging_removal_spec.rb @@ -0,0 +1,18 @@ +require "rails_helper" + +RSpec.describe "Removing a staff tagging", type: :system, js: true do + let(:admin) { create(:user, :admin) } + let(:person) { create(:person, first_name: "Alma", last_name: "Alphason") } + let!(:tagging) { create(:staff_tagging, staff_taggable: person) } + + before { sign_in admin } + + it "deletes the tagging from its edit page" do + visit edit_staff_tagging_path(tagging, return_to: "staff_taggings") + + accept_confirm { click_link "Remove tagging" } + + expect(page).to have_content("Staff tagging was successfully removed.") + expect(StaffTagging.exists?(tagging.id)).to be(false) + end +end