From 8aaa81461d0d5f31ec5de1bebd853dccd69025a4 Mon Sep 17 00:00:00 2001 From: Koji Takao Date: Wed, 21 Jan 2026 21:55:14 +0900 Subject: [PATCH] Fix ActionController::ForceSSL compatibility with Rails 8.0+ Issue #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 --- lib/jsonapi/resource_controller_metal.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/jsonapi/resource_controller_metal.rb b/lib/jsonapi/resource_controller_metal.rb index e8dfb3f5..514b2b67 100644 --- a/lib/jsonapi/resource_controller_metal.rb +++ b/lib/jsonapi/resource_controller_metal.rb @@ -2,12 +2,20 @@ module JSONAPI class ResourceControllerMetal < ActionController::Metal + # ActionController::ForceSSL was removed in Rails 8.0 + # It existed in Rails < 6.1, and force_ssl is now integrated into ActionController::Base + FORCE_SSL_MODULE = if Gem::Requirement.new('< 6.1').satisfied_by?(ActionPack.gem_version) + defined?(ActionController::ForceSSL) ? ActionController::ForceSSL : nil + else + nil + end + MODULES = [ AbstractController::Rendering, ActionController::Rendering, ActionController::Renderers::All, ActionController::StrongParameters, - Gem::Requirement.new('< 6.1').satisfied_by?(ActionPack.gem_version) ? ActionController::ForceSSL : nil, + FORCE_SSL_MODULE, ActionController::Instrumentation, JSONAPI::ActsAsResourceController ].compact.freeze