Repository navigation
Add applied_filter_params, the values as a copy - #8
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Shared mutable String values allow edits through the new helper to alter the original filters.
1 open issue
What changed in this PR
Adds applied_filter_params for controllers and views to translate effective filters without changing the existing filtering_params API.
Changes:
- Adds and exposes the indifferent-access copy helper.
- Documents its intended usage and tests symbol access and key mutation.
- Corrects a return-type annotation and bumps the version to 1.2.0.
| File | Description |
|---|---|
| spec/data_access_spec.rb | Tests helper access and key-mutation isolation. |
| README.md | Documents the new helper. |
| lib/active_admin_filter_extensions/version.rb | Bumps version to 1.2.0. |
| lib/active_admin_filter_extensions/filter_defaults.rb | Implements the helper and corrects the annotation. |
| lib/active_admin_filter_extensions.rb | Exposes the helper to views. |
Review effort: Balanced
A page that builds its own collection or its own links usually has to translate the effective filters before passing them on: rename a key an input suffixed, turn a sentinel value into a different predicate. Doing that to what #filtering_params returns edits the Hash that also fills the filters form and decides the canonicalizing redirect, and the String keys make every such site reach for symbolize/stringify first. #applied_filter_params is the same values as an indifferent deep copy - readable by symbol, safe to mutate, down to the value objects. #filtering_params keeps its contract untouched: the exact Hash handed to Ransack.
Fivell
force-pushed
the
applied-filter-params
branch
from
October 20, 2026 06:44
80bc785 to
39cf196
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why
filtering_paramsis documented as the values handed to Ransack, and that is exactly what it returns: aHashwith String keys, the same object the filters form and the canonicalizing redirect are computed from.That is the right contract for the framework path, and an awkward one for a page that does its own work with those values. Such a page — one that overrides
find_collectionwithoutsuper, talks to something that is not anActiveRecord::Relation, or builds a drill-down or export link — usually has to translate the filters first: rename a key an input suffixed (time_start_gteq_datetime→time_start_gteq), turn a sentinel select value into a different predicate (status_eq=null→status_null=true). Done on the returned Hash, that edits what fills the filters form and what the redirect decision is computed from; done safely, every site repeats.with_indifferent_accessorsymbolize_keysplus adupof its own.What
Registered as a helper next to
filtering_params, so a view can call it too.filtering_paramsis untouched — same contract, same type, same object semantics.Tests
spec/data_access_spec.rb— one example reads by symbol a value the request spelled as a String; the other mutates the result the way a translating page does (applied[:position_gt] = applied.delete(:position_eq)) and asserts both thatfiltering_paramsis unchanged and that Ransack still searched the original.Full suite: 200 examples, 0 failures. Version bumped to 1.2.0.
Also fixes a stale annotation:
filtering_paramswas documented as[Hash, ActionController::Parameters], butrequested_filtering_paramsunwrapsParametersviato_unsafe_h, so it is always aHash.