Skip to content

Fix ActionController::ForceSSL compatibility with Rails 8.0+ (Issue #1477)#23

Merged
takaokouji merged 1 commit intomasterfrom
fix/rails-8-forcessl-compatibility
Jan 21, 2026
Merged

Fix ActionController::ForceSSL compatibility with Rails 8.0+ (Issue #1477)#23
takaokouji merged 1 commit intomasterfrom
fix/rails-8-forcessl-compatibility

Conversation

@takaokouji
Copy link
Collaborator

Summary

Fixes ActionController::ForceSSL compatibility issue with Rails 8.0+, addressing part of Issue JSONAPI-Resources#1477.

Issue JSONAPI-Resources#1477

  • Problem 1: ActionController::ForceSSL was removed in Rails 8.0, causing uninitialized constant errors
  • Problem 2: Validation errors returning status code 0 instead of 422

This PR addresses Problem 1.

Changes

  • Added FORCE_SSL_MODULE constant with proper version and existence checking
  • Only includes ForceSSL module for Rails < 6.1 where it actually exists
  • Uses defined?() check to prevent NameError in Rails 8.0+

Code Changes

# Before (Rails 8.0 error):
Gem::Requirement.new('< 6.1').satisfied_by?(ActionPack.gem_version) ? ActionController::ForceSSL : nil

# After (Rails 8.0 compatible):
FORCE_SSL_MODULE = if Gem::Requirement.new('< 6.1').satisfied_by?(ActionPack.gem_version)
                     defined?(ActionController::ForceSSL) ? ActionController::ForceSSL : nil
                   else
                     nil
                   end

Background

  • ActionController::ForceSSL existed in Rails < 6.1
  • It was removed in Rails 8.0
  • force_ssl functionality is now integrated directly into ActionController::Base

Test Results

Tested on Rails 8.0.4:

  • No ForceSSL NameError
  • Resource tests pass
  • Validation tests pass (returning correct 422 status)

Related

Note on Problem 2

The validation status code issue (Problem 2) was not reproducible in our tests. All validation tests correctly return 422 status code on Rails 8.0.4. This may have been fixed in other changes or may require specific reproduction steps.

Issue JSONAPI-Resources#1477 reported:
- ActionController::ForceSSL was removed in Rails 8.0
- Previous code caused 'uninitialized constant' error

Changes:
- Check if ActionController::ForceSSL is defined before using it
- Added FORCE_SSL_MODULE constant with proper version checking
- Only include ForceSSL for Rails < 6.1 where it exists

Note:
- ForceSSL existed in Rails < 6.1 and was removed in Rails 8.0
- force_ssl functionality is now integrated into ActionController::Base
- This fix prevents NameError on Rails 8.0+

Tested on:
- Rails 8.0.4: All tests pass, no ForceSSL errors
@takaokouji takaokouji merged commit 0513b04 into master Jan 21, 2026
60 checks passed
@takaokouji takaokouji deleted the fix/rails-8-forcessl-compatibility branch January 21, 2026 13:02
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