diff --git a/lib/jsonapi/acts_as_resource_controller.rb b/lib/jsonapi/acts_as_resource_controller.rb index b8d75ae74..032841608 100644 --- a/lib/jsonapi/acts_as_resource_controller.rb +++ b/lib/jsonapi/acts_as_resource_controller.rb @@ -152,7 +152,7 @@ def resource_serializer_klass end def base_url - @base_url ||= request.protocol + request.host_with_port + @base_url ||= "#{request.protocol}#{request.host_with_port}#{Rails.application.config.relative_url_root}" end def resource_klass_name diff --git a/test/controllers/controller_test.rb b/test/controllers/controller_test.rb index 7d266792f..f71370322 100644 --- a/test/controllers/controller_test.rb +++ b/test/controllers/controller_test.rb @@ -10,6 +10,13 @@ def setup JSONAPI.configuration.always_include_to_one_linkage_data = false end + def test_links_include_relative_root + Rails.application.config.relative_url_root = '/subdir' + assert_cacheable_get :index + assert json_response['data'][0]['links']['self'].include?('/subdir') + Rails.application.config.relative_url_root = nil + end + def test_index assert_cacheable_get :index assert_response :success