Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

NameError: uninitialized constant JSONAPI::ResourceController in Rails 7.1

Offen
#1,464 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Ein zugehöriger Pull Request wurde bereits gemerged.

  • #18 von @takaokouji — gemerged

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
rails, ruby
Bereich
api, backend

Rechercherichtung

Beginnen Sie mit den Zeilen 12–18 von lib/jsonapi-resources.rb und dem Ladepfad, der von app/controllers/jsonapi/v1/base_controller.rb verwendet wird. Reproduzieren Sie den intermittierenden Fehler über test/controllers/jsonapi/v1/team_projects_controller_test.rb unter Ruby 3.3.6 und Rails 7.1.5.1. Als abgeschlossen gilt die Aufgabe, wenn die Testsuite den Fehler wegen einer nicht initialisierten Konstante nicht mehr auslöst, ohne dass Eager Loading oder der gemeldete Controller-Workaround erforderlich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

This issue is a (choose one):

  • Problem/bug report.
  • Feature request.
  • Request for support. Note: Please try to avoid submitting issues for support requests. Use Gitter instead.

Checklist before submitting:

  • I've searched for an existing issue.
  • I've NOT asked my question on Gitter because Gitter seems to be abandoned by the core team. There a lots of questions posted there that have no responses at all.
  • I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
  • The feature I'm asking for is compliant with the JSON:API spec.

Description

In trying to update to Rails 7.1 I'm running into random instances of this error when running my test suite.

Error:
Jsonapi::V1::TeamProjectsControllerTest#test_should_not_create_for_a_forbidden_team:
NameError: uninitialized constant JSONAPI::ResourceController
    app/controllers/jsonapi/v1/base_controller.rb:3:in `<main>'
    app/controllers/jsonapi/v1/team_projects_controller.rb:1:in `<main>'
    test/controllers/jsonapi/v1/team_projects_controller_test.rb:126:in `block in <class:TeamProjectsControllerTest>'

Sometimes there will be 2 of them, other times 20 or 30.

Via some trial and error I discovered that if I alter my BaseController to look like this:

class Jsonapi::V1::BaseController < ActionController::Base
  include JSONAPI::ActsAsResourceController
  # ...
end

Instead of this:

class Jsonapi::V1::BaseController < JSONAPI::ResourceController
  # ...
end

then the random errors go away.

I also noticed that these errors were only happening locally, and not in CI, and so I tried setting config.eager_load = true in config/environments/test.rb which also made the errors go away.

I poked around this gem a little bit and I think that this block of code isn't exactly working as expected in Rail 7.1.

https://github.com/cerebris/jsonapi-resources/blob/e92afc690f5c53da6f4fa5e91ca72a50873390be/lib/jsonapi-resources.rb#L12-L18

Ruby: 3.3.6
Rails: 7.1.5.1

Vorherrschende Sprache
Ruby
Sterne
2.3k
Forks
547
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus JSONAPI-Resources/jsonapi-resources

Alle Issues in JSONAPI-Resources/jsonapi-resources

Ähnliche Issues

Weitere Issues zu Ruby

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.