Skip to content

Modernize for Rails 7/8: dependency-free JS, form_with support, pluggable data source - #69

Merged
arvindvyas merged 4 commits into
masterfrom
modernization-v4
Jul 5, 2026
Merged

Modernize for Rails 7/8: dependency-free JS, form_with support, pluggable data source#69
arvindvyas merged 4 commits into
masterfrom
modernization-v4

Conversation

@arvindvyas

Copy link
Copy Markdown
Owner

Summary

  • Drops the jQuery/Chosen requirement in favor of a dependency-free JS core with a bundled Stimulus controller, shipped for importmap-rails, Sprockets, and npm/esbuild/webpack. The legacy jQuery/Chosen build is kept for backward compatibility but deprecated.
  • Adds native form_with/form_for support (f.country_select, f.state_select, f.city_select) so simple_form is no longer required; existing simple_form usage is unchanged.
  • Adds a pluggable data source (CountryStateSelect::DataSources::Base), priority_countries/only/except filtering, flag emoji + dial code labels, and I18n-localized country names.
  • Adds HTTP caching (Cache-Control/ETag) to the /find_states//find_cities JSON endpoints, and a documented pattern for mounting them at a custom path.
  • Adds an install generator (rails g country_state_select:install).
  • Adds a runnable Rails 7/8 demo app under spec/dummy (Propshaft + importmap + Stimulus) that doubles as the integration test target, plus request/unit specs for all of the above.
  • Expands CI to a Rails 7.0/7.1/7.2/8.0 matrix alongside the Ruby version matrix.
  • Requires Rails >= 7.0 and Ruby >= 3.1 going forward (drops the Rails 3–6 engine3.rb/railtie.rb code paths); the 3.x gem remains available for older Rails.

See CHANGELOG.md and docs/migration-v4.md for the full list and upgrade notes.

Test plan

  • bundle exec rspec — 58 examples, 0 failures (default Gemfile, latest Rails)
  • Same suite green against gemfiles/rails_7.0.gemfile, rails_7.1.gemfile, rails_7.2.gemfile, rails_8.0.gemfile
  • Manually drove the demo app (spec/dummy) in a real browser: country → state → city cascade over AJAX, aria-live announcements, and an edit-page load correctly pre-populates the saved state/city with zero extra AJAX calls
  • bundle exec bundler-audit check --update — no vulnerabilities

Comment thread spec/dummy/app/controllers/application_controller.rb Fixed
…able data source

Drops the jQuery/Chosen requirement in favor of a dependency-free JS core
with a bundled Stimulus controller (importmap-rails, Sprockets, and npm
builds), adds native form_with/form_for helpers so simple_form is no
longer required, and introduces a pluggable data source with
priority/only/except country filtering, flags, dial codes, and I18n
localization. HTTP caching is added to the JSON lookup endpoints, and a
new install generator sets up the initializer.

Requires Rails >= 7.0 and Ruby >= 3.1 going forward (3.x remains for
older Rails). The legacy jQuery/Chosen JS keeps working, deprecated.

Adds a runnable Rails 7/8 demo app under spec/dummy (Propshaft +
importmap + Stimulus) that doubles as the integration test target, and
expands CI to a Rails 7.0/7.1/7.2/8.0 matrix alongside the Ruby matrix.

See CHANGELOG.md and docs/migration-v4.md for details.
The CI matrix runs the dummy app across Ruby 3.1-3.4; pinning it to the
one version it happened to be generated under is misleading.
Flagged by CodeQL: it was missing protect_from_forgery, which rails new
includes by default. The lookup controller's own skip_forgery_protection
for its read-only GET endpoints is unaffected.
db/schema.rb and the migration were checked in with
ActiveRecord::Schema[8.1]/Migration[8.1], generated on my local Rails
8.1. That version doesn't exist on Rails 7.0/7.1/7.2/8.0, so a fresh
`db:test:load_schema` (as CI does) raised "Unknown migration version
8.1" and every request spec failed with "Could not find table
'businesses'". It passed in my local testing across those gemfiles
only because the local test.sqlite3 already had the table from an
earlier run and never needed to reload schema.rb.

Pinned both to 7.0, the floor of the supported range, and verified
against a freshly deleted test.sqlite3 across the default Gemfile and
all 4 pinned Rails versions.
@arvindvyas
arvindvyas merged commit 6ba0a70 into master Jul 5, 2026
10 checks passed
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