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.

### New Feature Submissions:

- [ ] I've submitted an issue that describes this feature, and received the go ahead from the maintainers.
- [ ] My submission includes new tests.
- [ ] My submission maintains compliance with JSON:API.

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

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.
@simps614 simps614 closed this Jan 20, 2026
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

1 participant