Skip to content

Explain why a resource could not be destroyed - #9155

Open
senid231 wants to merge 1 commit into
activeadmin:masterfrom
senid231:destroy-errors
Open

senid231 wants to merge 1 commit into
activeadmin:masterfrom
senid231:destroy-errors

Conversation

@senid231

@senid231 senid231 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

When a record can't be destroyed, the alert now says why.

Before, the responders gem set "Post could not be destroyed." and dropped resource.errors, as with dependent: :restrict_with_error or a before_destroy that adds an error. A dependent: :restrict_with_exception association raised ActiveRecord::DeleteRestrictionError out of the action, which returned a 500 error. The destroy action now appends resource.errors.full_messages to the alert. It also rescues the restriction error into the record's errors and redirects with the alert.

The rescue sits in the action, not in destroy_resource, because the default batch delete also calls destroy_resource. Rescuing there would have turned the batch's error into "Successfully destroyed N posts" for records that still exist. A spec pins the batch behavior. The batch already reports success for restrict_with_error records today; this PR leaves that alone.

Raised in #9147; #5369 asked for the same in 2023. Request specs cover both restriction types and a successful destroy.

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (e1dad93) to head (6a0c464).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9155   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         139      139           
  Lines        4071     4078    +7     
=======================================
+ Hits         4035     4042    +7     
  Misses         36       36           

☔ View full report in Codecov by Harness.
📢 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.

The alert said only that the record could not be destroyed and dropped
its errors. A restrict_with_exception association raised
DeleteRestrictionError out of the action and returned a 500 error; it
now adds the error to the record and redirects with the alert.

Co-Authored-By: Clanker

This branch has not been deployed

No deployments
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.

1 participant