Skip to content

Redirect to comments index when deleting it from its own show page#9031

Open
Fivell wants to merge 1 commit into
masterfrom
fix-7770-comments-destroy-redirect
Open

Redirect to comments index when deleting it from its own show page#9031
Fivell wants to merge 1 commit into
masterfrom
fix-7770-comments-destroy-redirect

Conversation

@Fivell

@Fivell Fivell commented May 23, 2026

Copy link
Copy Markdown
Member

Closes #7770.

Previously, deleting a comment from /admin/comments/:id redirected back to that same URL (via redirect_back), which then 404'd because the comment had just been destroyed.

The existing redirect_back is the right behavior when the comment is deleted from the commentable resource's page (e.g. /admin/posts/5) -- the user wants to return there. Only the self-referencing case is broken.

Check the referer against the deleted comment's own path and redirect to the comments index when they match; otherwise keep redirect_back.

A new cucumber scenario exercises the broken path (delete from the comment show page) and asserts the user lands on the comments index.

…page

Closes #7770.

Previously, deleting a comment from `/admin/comments/:id` redirected
back to that same URL (via `redirect_back`), which then 404'd because
the comment had just been destroyed.

The existing `redirect_back` is the right behavior when the comment is
deleted from the commentable resource's page (e.g. `/admin/posts/5`) --
the user wants to return there. Only the self-referencing case is
broken.

Check the referer against the deleted comment's own path and redirect
to the comments index when they match; otherwise keep `redirect_back`.

A new cucumber scenario exercises the broken path (delete from the
comment show page) and asserts the user lands on the comments index.
@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (5164bbb) to head (a19a0e2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9031   +/-   ##
=======================================
  Coverage   99.08%   99.08%           
=======================================
  Files         139      139           
  Lines        4040     4042    +2     
=======================================
+ Hits         4003     4005    +2     
  Misses         37       37           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Fivell Fivell requested review from Copilot and javierjulio and removed request for Copilot May 23, 2026 19:15
@Fivell Fivell requested a review from tagliala May 23, 2026 19:15
# to the comments index instead -- otherwise redirect_back
# would return to a now-404 page. Deleting from a
# commentable resource still redirects back to that resource.
if request.referer && URI(request.referer).path == admin_comment_path(id: params[:id])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally avoid dealing with the Referer header, even if that means living with the bug for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tagliala yes, I agree. We should avoid relying on that header. @Fivell I've been aware of this bug but didn't seem clear how to reliably resolve it. Since the issue is from the admin/comments page which is implemented internally, could we set a parameter in the request to then change the redirect behavior here only for that page?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javierjulio @tagliala thanks for your comments, I'll try alternative implementation this friday and let you know

@Fivell Fivell self-assigned this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrong redirect url after delete comment from show page of Comment

3 participants