JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Rails 4.2 with Ruby 2.4.9: undefined method `root' for JSONAPI::Rails:Module
Offen
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 546
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
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 asked my question on Gitter and have not received a satisfactory answer.
- 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
As the title: controller raises the exception:
E, [2020-10-29T02:29:40.427579 #92859] ERROR -- : Internal Server Error: undefined method `application' for JSONAPI::Rails:Module /*/.rbenv/versions/2.4.9/lib/ruby/gems/2.4.0/gems/jsonapi-resources-0.10.2/lib/jsonapi/acts_as_resource_controller.rb:155:in `base_url'
which can be fixed with
def base_url
- @base_url ||= "#{request.protocol}#{request.host_with_port}#{Rails.application.config.relative_url_root}"
+ @base_url ||= "#{request.protocol}#{request.host_with_port}#{::Rails.application.config.relative_url_root}"
end
# config/routes.rb
namespace :api do
jsonapi_resources :tests, only: %i[index]
end
# app/controllers/api/tests_controller.rb
module Api
class TestsController < ::Api::BaseController
end
end
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei lib/jsonapi/acts_as_resource_controller.rb:155, wo base_url zusammengesetzt wird, und überprüfe die dort verwendete Rails-Anwendungsreferenz. Reproduziere die Anfrage anhand des Api::TestsController-Beispiels in config/routes.rb und überprüfe anschließend, dass sie nicht mehr den undefined-method-Fehler auslöst und weiterhin die erwartete base URL erstellt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rails, ruby
- Bereich
- api, backend
- Issue-Typ
- Bug
- Schwierigkeit
- 1/5
- Geschätzter Aufwand
- Unter einer Stunde
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100