Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Rails 4.2 with Ruby 2.4.9: undefined method `root' for JSONAPI::Rails:Module

Đang mở
#1,332 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rails, ruby
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu tại lib/jsonapi/acts_as_resource_controller.rb:155, nơi base_url được tạo, và xem xét tham chiếu đến ứng dụng Rails được sử dụng ở đó. Tái hiện request thông qua ví dụ Api::TestsController trong config/routes.rb, sau đó xác minh rằng request không còn gây ra lỗi undefined-method và vẫn tạo được base URL như mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Ruby
Star
2.3k
Fork
546
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JSONAPI-Resources/jsonapi-resources

Tất cả issue của JSONAPI-Resources/jsonapi-resources

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.