Skip to content

Conversation

@simps614
Copy link

Fixes #1479

Rails 8.1 changed ActionDispatch::Routing::Mapper::Resources::Resource#initialize to require keyword args (only:, except:, **options). The JSONAPI‑Resources DSL still passes a positional options hash, so jsonapi_relationships never runs and relationship routes are missing.

Adding the ** operator to **options converts the hash into keyword args.

Tests that fail without this change: test/controllers/controller_test.rb

I ran into several other deprecations.

  • ActiveSupport::Deprecation.silenced will not work the way it was set up in the tests because #silenced now works on an instance of Deprecators instead of globally. I created a module JSONAPI.deprecator so that the gem can use its own instance of Deprecator and the tests can work as designed.
  • :unprocessable_entity was deprecated in favor of :unprocessable_content
  • Used lazy method evaluation for Configuration because Rails 8.1 does not guarantee class-body initialization order, so @configuration was returning nil.
  • My team uses an active_record oracle adapter. Oracle unquoted identifiers are automatically stored as UPPERCASE. Rails 8.1 no longer normalizes the case automatically for queries, so I added a condition for using the oracle adapter.
  • length is no longer a valid column constraint. Used limit instead
  • references: is not a valid option key for ActiveRecord migrations. Excplicitly pass a foreign_key to the things table instead.
  • :none is not a valid active_record schema format in Rails 8.1
  • Disabled foreign key constraints for SQLite tests
  • Use ActiveRecord::Base.connection.quoted_true as it is database agnostic

There are a few warnings in the test suite that I did not address because they were unrelated to this change.

All Submissions:

  • I've checked to ensure there aren't other open Pull Requests for the same update/change.
  • I've submitted a ticket for my issue if one did not already exist.
  • My submission passes all tests. (Please run the full test suite locally to cut down on noise from travis failures.)
  • I've used Github auto-closing keywords in the commit message or the description.
  • I've added/updated tests for this change.

Bug fixes and Changes to Core Features:

  • I've included an explanation of what the changes do and why I'd like you to include them.
  • I've provided test(s) that fails without the change.

Reviewer Checklist:

  • Maintains compliance with JSON:API
  • Adequate test coverage exists to prevent regressions

NOTE: I used Ruby 3.2 locally. There are big changes since Ruby 2.6 so CI fails.

Fixes #1479

Rails 8.1 changed `ActionDispatch::Routing::Mapper::Resources::Resource#initialize`
to require keyword args (only:, except:, **options). The JSONAPI‑Resources
DSL still passes a positional options hash, so jsonapi_relationships never
runs and relationship routes are missing.

Adding the ** operator to `**options` converts the hash into keyword args.

Tests that fail without this change: `test/controllers/controller_test.rb`

I ran into several other deprecations.
* `ActiveSupport::Deprecation.silenced`
  will not work the way it was set up in the tests because `#silenced` now
  works on an instance of `Deprecators` instead of globally. I created a
  module `JSONAPI.deprecator` so that the gem can use its own instance
  of Deprecator and the tests can work as designed.
* `:unprocessable_entity` was deprecated in favor of `:unprocessable_content`
* Used lazy method evaluation for `Configuration` because Rails 8.1 does
  not guarantee class-body initialization order, so @configuration was returning
  `nil`.
* My team uses an active_record oracle adapter. Oracle unquoted identifiers
  are automatically stored as UPPERCASE. Rails 8.1 no longer normalizes
  the case automatically for queries, so I added a condition for using the
  oracle adapter.
* `length` is no longer a valid column constraint. Used `limit` instead
* `references:` is not a valid option key for ActiveRecord migrations.
  Excplicitly pass a foreign_key to the things table instead.
* `:none` is not a valid active_record schema format in Rails 8.1
* Disabled foreign key constraints for SQLite tests
* Use `ActiveRecord::Base.connection.quoted_true` as it is database agnostic

There are a few warnings in the test suite that I did not address because
they were unrelated to this change.
takaokouji added a commit to speee/jsonapi-resources that referenced this pull request Jan 21, 2026
This commit addresses several Rails 8.1 compatibility issues:

1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+
   (removed from standard library). Required by acts_as_resource_controller.rb.

2. **HTTP status code compatibility**: Updated :unprocessable_entity to
   use conditional :unprocessable_content for Rails 8.1+ to avoid deprecation
   warnings while maintaining backward compatibility with earlier Rails versions.
   - Added unprocessable_status helper in JSONAPI::Exceptions::Error
   - Updated ValidationErrors and SaveFailed exceptions
   - Updated test assertions in controller_test.rb

3. **Database adapter improvements**: Simplified db_true helper in
   join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true
   for database-agnostic boolean value handling.

These changes maintain full backward compatibility with Rails 6.1, 7.0,
7.1, 7.2, and 8.0 while preparing for Rails 8.1+.

Based on upstream PR: cerebris#1485

Co-Authored-By: Cassie Simpson <simps614@umn.edu>
@takaokouji
Copy link

Hi @simps614,

Thank you so much for your excellent work on Rails 8.1 compatibility! 🎉

I've incorporated several of your changes into the Speee fork of jsonapi-resources. Specifically, I adopted:

  1. CSV gem dependency - Added to Gemfile for Rails 8.1+ compatibility
  2. HTTP status code updates - Modified to conditionally use :unprocessable_content for Rails 8.1+ while maintaining backward compatibility with earlier Rails versions
  3. Database adapter improvements - Used ActiveRecord::Base.connection.quoted_true for cleaner, database-agnostic code

I made some slight modifications to maintain backward compatibility by only using :unprocessable_content when Rails::VERSION::MAJOR >= 8 && Rails::VERSION::MINOR >= 1, but the core improvements are directly from your PR.

The changes are available in: speee#24

If you're interested, we'd love for you to try out the Speee fork at https://github.com/speee/jsonapi-resources! We've been working on maintaining compatibility with recent Rails versions and would appreciate any feedback.

Thanks again for your contribution to the jsonapi-resources community!

takaokouji added a commit to speee/jsonapi-resources that referenced this pull request Jan 21, 2026
This commit addresses several Rails 8.1 compatibility issues:

1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+
   (removed from standard library). Required by acts_as_resource_controller.rb.

2. **HTTP status code compatibility**: Updated :unprocessable_entity to
   use conditional :unprocessable_content for Rails 8.1+ to avoid deprecation
   warnings while maintaining backward compatibility with earlier Rails versions.
   - Added unprocessable_status helper in JSONAPI::Exceptions::Error
   - Updated ValidationErrors and SaveFailed exceptions
   - Updated test assertions in controller_test.rb

3. **Database adapter improvements**: Simplified db_true helper in
   join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true
   for database-agnostic boolean value handling.

These changes maintain full backward compatibility with Rails 6.1, 7.0,
7.1, 7.2, and 8.0 while preparing for Rails 8.1+.

Based on upstream PR: cerebris#1485

Co-Authored-By: Cassie Simpson <simps614@umn.edu>
takaokouji added a commit to speee/jsonapi-resources that referenced this pull request Jan 21, 2026
This commit addresses several Rails 8.1 compatibility issues:

1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+
   (removed from standard library). Required by acts_as_resource_controller.rb.

2. **HTTP status code compatibility**: Updated :unprocessable_entity to
   use conditional :unprocessable_content for Rails 8.0+ to avoid deprecation
   warnings while maintaining backward compatibility with earlier Rails versions.
   - Added unprocessable_status helper in JSONAPI::Exceptions::Error
   - Updated ValidationErrors and SaveFailed exceptions
   - Updated test assertions in controller_test.rb and test helpers

3. **Database adapter improvements**: Simplified db_true helper in
   join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true
   for database-agnostic boolean value handling.

These changes maintain full backward compatibility with Rails 6.1, 7.0,
and 7.1 while preparing for Rails 8.0+.

Based on upstream PR: cerebris#1485

Co-Authored-By: Cassie Simpson <simps614@umn.edu>
@simps614
Copy link
Author

@takaokouji thank you for addressing this so quickly! I tried the fork on two of our applications and it is working. Do you know when we could expect a release?

@umn-asr umn-asr closed this by deleting the head repository Jan 21, 2026
@takaokouji
Copy link

takaokouji commented Jan 22, 2026

@simps614
Great to hear it's working for your applications!

We've just released v26.1.2 which includes these fixes. You can try it out by adding the following to your Gemfile:

gem 'jsonapi-resources', git: 'https://github.com/speee/jsonapi-resources.git', tag: 'v26.1.2'

Or if you prefer to use the latest from master:

gem 'jsonapi-resources', git: 'https://github.com/speee/jsonapi-resources.git'

Release notes: https://github.com/speee/jsonapi-resources/releases/tag/v26.1.2

Please let us know if you encounter any issues!

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.

Rails 8.1: jsonapi_resources DSL fails to generate relationship routes due to Resource#initialize signature change

3 participants