Skip to content

Let an app move the notice flash key once - #7

Merged
Fivell merged 1 commit into
mainfrom
notice-flash-key-default
Oct 19, 2026
Merged

Fivell merged 1 commit into
mainfrom
notice-flash-key-default

Conversation

@Fivell

@Fivell Fivell commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Why

default_filters_notice takes flash_key: per resource, defaulting to :notice. An application that renders its own flash key for "why this page is cut down" therefore repeats it on every index that declares a notice — or reaches for a prepend on ActiveAdmin::ResourceDSL to move the default, which is monkeypatching the DSL to change one default value. Nothing in the gem offered a place to say it once.

The key is not cosmetic. Active Admin writes action results to :notice, and Redirect resolves a collision in favour of the arriving message (redirect.rb:69-76), so on a shared key an action's result silences the filters notice. That matters for an index that both declares default filters and is where create/update/batch actions land — the admin learns why the page is cut down only on visits where they did nothing. An application like that needs a key of its own, and should be able to choose it once.

What

# config/initializers/active_admin_filter_extensions.rb
ActiveAdminFilterExtensions.notice_flash_key = :filters_notice
  • Default stays :notice — nothing changes for an application that says nothing.
  • Resolved when the notice is written, not when the resource is registered (Notice.flash_key_for), so initializer order cannot decide it and both writers — the before_action and the redirect's travelling flash — go through one method.
  • flash_key: on the resource still wins.

Tests

spec/integration/filter_defaults_spec.rb, under default_filters_notice: one example moves the app-wide key around a single request and asserts the rendered flash class (.flash_filters_notice present, .flash_notice absent); the other checks that a resource which declared its own key keeps it.

The first example discriminates the design, not just the accessor: had the key been captured at registration, moving it after boot would leave the notice on :notice and the assertion would fail.

Full suite: 198 examples, 0 failures. Version bumped to 1.1.0.

@Fivell
Fivell force-pushed the notice-flash-key-default branch 2 times, most recently from db0f983 to 0cc8e39 Compare October 19, 2026 17:17
@Fivell
Fivell requested a balanced review from Copilot October 19, 2026 17:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The resource-precedence test uses identical keys and cannot detect a broken override.

1 open issue
What changed in this PR

Adds an application-wide flash key for default-filter notices while preserving resource-specific overrides and the existing :notice default.

Changes:

  • Resolves notice keys at write time through a shared helper.
  • Documents configuration and adds integration coverage.
  • Bumps the version to 1.1.0.
File Description
spec/​integration/​filter_defaults_spec.rb Tests global configuration and resource precedence.
README.md Documents application-wide configuration.
lib/​active_admin_filter_extensions/​version.rb Bumps version to 1.1.0.
lib/​active_admin_filter_extensions/​redirect.rb Uses shared key resolution for redirects.
lib/​active_admin_filter_extensions/​notice.rb Resolves resource and application keys at write time.
lib/​active_admin_filter_extensions.rb Adds the application-wide setting.

Review effort: Balanced

Comment thread spec/integration/filter_defaults_spec.rb
`flash_key:` was per resource, so an application that renders its own flash key
for "why this page is cut down" had to repeat it on every index declaring a
notice - or reach for a prepend on ResourceDSL to move the default.

`ActiveAdminFilterExtensions.notice_flash_key` is that default. It is read when
the notice is written rather than when the resource is registered, so
initializer order does not decide it and a test can move it around one request.
What the resource declared still wins.
@Fivell
Fivell force-pushed the notice-flash-key-default branch from 0cc8e39 to efa55ef Compare October 19, 2026 17:30
@Fivell
Fivell requested a balanced review from Copilot October 19, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused change preserves existing defaults and resource overrides, with no unresolved findings.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@Fivell
Fivell merged commit 46b7caf into main Oct 19, 2026
7 checks passed
@Fivell
Fivell deleted the notice-flash-key-default branch October 19, 2026 17:39
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.

2 participants