Skip to content

Default to case-insensitive string filters on ransack 6 - #9134

Draft
tagliala wants to merge 8 commits into
masterfrom
ransack-6
Draft

tagliala wants to merge 8 commits into
masterfrom
ransack-6

Conversation

@tagliala

@tagliala tagliala commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Ransack 6 makes the cont, start and end predicates case-sensitive on PostgreSQL: they now generate LIKE instead of ILIKE. ActiveAdmin string filters used these predicates by default, so on PostgreSQL searching a name for "mar" would no longer find "Mario". The Dependabot bump to ransack 6 (#9133) could not be merged as is for this reason.

Requiring a newer ransack is not an option: ransack 6.1 (unreleased) only supports Rails 8.1+ (activerecord-hackery/ransack#1786, #9135), while ActiveAdmin still supports Rails 7.2 and 8.0.

Solution

  • ActiveAdmin::Inputs::Filters::StringInput.filters returns i_cont, eq, i_start and i_end when the loaded ransack provides the i_start predicate (ransack 6.0+), and cont, eq, start and end otherwise. The check uses Ransack::Predicate.named, available since ransack 4.0, rather than Ransack::VERSION, so git checkouts and prereleases resolve correctly.
  • The minimum stays at ransack >= 4.0.
  • Labels keep using Ransack::Translate.predicate. Ransack 6.0 has no translations for the i_* predicates, so the filter select and the active filters show the raw names (e.g. "i_cont"); ransack 6.1 translates them ("contains, ignoring case", Translate the predicates missing from every locale activerecord-hackery/ransack#1744).
  • filter_method_for_large_association keeps its "_start" default; the upgrade notes explain how to switch to "_i_start".

Compatibility

Gemfile Rails ransack Default string predicates i_* labels
gemfiles/rails_72 7.2 ~> 5.0 (5.0.2) cont, eq, start, end n/a
gemfiles/rails_80 8.0 ~> 6.0.0 (6.0.0) i_cont, eq, i_start, i_end raw
Gemfile 8.1 latest (6.0.0) i_cont, eq, i_start, i_end raw until 6.1

The lockfile changes are limited to ransack.

Upgrade notes

UPGRADING.md and docs/3-index-pages.md explain that:

  • the default depends on the installed ransack;
  • with ransack 6 on PostgreSQL, custom string_input_filters, filters: options, filter :name_cont and filter_method_for_large_association = "_start" become case-sensitive and should switch to the i_* predicates;
  • ransack 6.0 shows the i_* predicates untranslated; ransack 6.1 translates them but requires Rails 8.1, so applications on earlier Rails versions stay on ransack 6.0 and can add their own ransack.predicates translations;
  • bookmarked URLs with the previous parameters (e.g. q[title_cont]) still filter, but the sidebar shows that filter empty with its first predicate selected.

Verification

Specs and features derive the expected predicate from StringInput.filters and the expected label from Ransack::Translate.predicate, so the same assertions hold with translated and untranslated i_* labels. A spec stubs Ransack::Predicate.named("i_start") to cover both defaults.

  • Rails 8.1, ransack 6.0.0: full RSpec (parallel and filesystem-changes) and full Cucumber (parallel, filesystem-changes and class-reloading profiles) pass.
  • Rails 8.1, ransack main (2910edab, translated i_* labels): the same full RSpec and Cucumber runs pass.
  • Rails 8.0, ransack 6.0.0 and Rails 7.2, ransack 5.0.2: spec/unit/filters, spec/helpers/filter_form_helper_spec.rb and features/index/filters.feature pass.
  • PostgreSQL 18, Rails 8.1, ransack 6.0.0: the default name_i_cont and name_i_start with "mar" generate ILIKE and find "Mario"; name_cont and name_start generate LIKE and find nothing.
  • rubocop on the changed files.

Supersedes #9133.

🤖 Generated with Claude Code

tagliala and others added 3 commits October 20, 2026 09:08
Raise the minimum ransack version to 6.0 in the gemspec and the
development Gemfiles, and update the lockfiles to ransack 6.0.0.

Supersedes #9133.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ransack 6 makes the cont, start and end predicates case-sensitive on
PostgreSQL by generating LIKE instead of ILIKE. String filters used
them by default, so searching "mar" no longer found "Mario" there.

Default string filters to i_cont, eq, i_start and i_end, which stay
case-insensitive on every database.

Ransack locales do not translate the i_* predicates, so the filter
select and the active filters would show the raw "i_cont" key. Add
ActiveAdmin::Filters.predicate_label, which falls back to the
translation of the case-sensitive counterpart unless the i_* predicate
has its own translation, and use it in both places.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Explain that string filters default to the i_* predicates, that cont,
start and end are case-sensitive on PostgreSQL with ransack 6, and how
to keep case-insensitive matching for custom string filter settings,
predicate filters and filter_method_for_large_association.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tagliala

Copy link
Copy Markdown
Contributor Author

Final state of the default string filter (SQLite test app): the Title filter uses title_i_cont, its select and the Active Search entry still read "Contains" / "Title contains".

Posts index with the Title filter set to Contains mar and the Active Search sidebar showing Title contains mar

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.11%. Comparing base (cae41ce) to head (97ca187).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9134   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         139      139           
  Lines        4071     4079    +8     
=======================================
+ Hits         4035     4043    +8     
  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.

@tagliala
tagliala requested review from javierjulio and removed request for javierjulio October 20, 2026 07:17
@tagliala
tagliala marked this pull request as draft October 20, 2026 07:50
@tagliala

tagliala commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Update: this PR is no longer blocked on ransack 6.1.0.

ransack 6.1 will only support Rails 8.1+ (activerecord-hackery/ransack#1786, #9135), so raising the minimum is not an option while ActiveAdmin supports Rails 7.2 and 8.0. The PR now keeps ransack >= 4.0, picks the i_* string predicates only when the loaded ransack provides i_start (6.0+), and drops ActiveAdmin::Filters.predicate_label. With ransack 6.0 the i_* labels show raw; ransack 6.1 translates them.

🤖 Generated with Claude Code

@scarroll32

Copy link
Copy Markdown

@tagliala see also #9135

tagliala and others added 5 commits October 20, 2026 14:32
Keep supporting ransack >= 4.0: ransack 6.1 will only support
Rails 8.1+, so applications on Rails 7.2 and 8.0 must be able to stay
on ransack 5.x or 6.0.

Exercise both major versions in CI: Rails 7.2 runs ransack 5.x,
Rails 8.0 runs ransack 6.0.x and Rails 8.1 runs the latest release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Drop the ActiveAdmin::Filters.predicate_label fallback that borrowed
the case-sensitive translation for i_* predicates. Ransack 6.1
translates i_* predicates itself; ransack 6.0 shows their raw names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default string filters to i_cont, eq, i_start and i_end when the loaded
ransack provides i_start (ransack 6.0+), and to cont, eq, start and end
otherwise. Ransack 6 makes cont, start and end case-sensitive on
PostgreSQL, so the i_* predicates keep the previous behavior there.

Check the predicate registry instead of Ransack::VERSION so prereleases
and git checkouts resolve correctly. Specs and features derive the
expected predicate and label from the loaded ransack, so they pass with
both translated and untranslated i_* predicates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Explain that string filters use the i_* predicates with ransack 6.0+,
that cont, start and end become case-sensitive on PostgreSQL with
ransack 6, and that ransack 6.0 shows i_* predicates untranslated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rendering a filter with a stubbed i_start predicate fails on ransack 5,
which cannot evaluate title_i_start on the search object. Compare the
default predicate list directly instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tagliala tagliala changed the title Require ransack 6 and default to case-insensitive string filters Default to case-insensitive string filters on ransack 6 Oct 20, 2026
@tagliala

Copy link
Copy Markdown
Contributor Author

Related upstream issue: activerecord-hackery/ransack#1788 asks for a 6.0.x release (and a 6-0-stable branch) that includes the missing i_cont, i_start and i_end translations from activerecord-hackery/ransack#1744. Until that ships, applications on Rails 7.2 or 8.0 with ransack 6.0.0 see the raw predicate keys in the filter select and in the active filters.

🤖 Generated with Claude Code

@scarroll32

Copy link
Copy Markdown

Ransack is now at 6.1.1 @tagliala

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.

2 participants