Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/jsonapi/rails/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def deserializable_resource(key, options = {}, &block)
end
end

def jsonapi_expose
{
url_helpers: ::Rails.application.routes.url_helpers
}
end

def jsonapi_pagination(_collection)
nil
end
Expand Down
7 changes: 3 additions & 4 deletions lib/jsonapi/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ class Railtie < ::Rails::Railtie
::ActionController::Renderers.add(:jsonapi) do |resources, options|
self.content_type ||= Mime[:jsonapi]

# Renderer proc is evaluated in the controller context, so it
# has access to the jsonapi_pagination method.
# Renderer proc is evaluated in the controller context.
if (pagination_links = jsonapi_pagination(resources))
(options[:links] ||= {}).merge!(pagination_links)
end
options[:expose] = jsonapi_expose.merge!(options[:expose] || {})

RENDERERS[:jsonapi].render(resources, options).to_json
end

::ActionController::Renderers.add(:jsonapi_error) do |errors, options|
# Renderer proc is evaluated in the controller context, so it
# has access to the jsonapi_pointers method.
# Renderer proc is evaluated in the controller context.
options = options.merge(_jsonapi_pointers: jsonapi_pointers)
self.content_type ||= Mime[:jsonapi]

Expand Down
5 changes: 0 additions & 5 deletions lib/jsonapi/rails/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def initialize(renderer = JSONAPI::Serializable::SuccessRenderer.new)

def render(resources, options)
opts = options.dup
# TODO(beauby): Move this to a global configuration.
default_exposures = {
url_helpers: ::Rails.application.routes.url_helpers
}
opts[:expose] = default_exposures.merge!(opts[:expose] || {})
opts[:jsonapi] = opts.delete(:jsonapi_object)

@renderer.render(resources, opts)
Expand Down