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
14 changes: 9 additions & 5 deletions lib/jsonapi/rails/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ def deserializable_resource(key, options = {}, &block)

before_action(options) do |controller|
hash = controller.params[:_jsonapi].to_unsafe_hash
JSONAPI::Parser::Resource.parse!(hash)
resource = klass.new(hash[:data])
controller.request.env[JSONAPI_POINTERS_KEY] =
resource.reverse_mapping
controller.params[key.to_sym] = resource.to_hash
ActiveSupport::Notifications.instrument('parse.jsonapi',
payload: hash,
class: klass) do
JSONAPI::Parser::Resource.parse!(hash)
resource = klass.new(hash[:data])
controller.request.env[JSONAPI_POINTERS_KEY] =
resource.reverse_mapping
controller.params[key.to_sym] = resource.to_hash
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/jsonapi/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class Railtie < ::Rails::Railtie
# Renderer proc is evaluated in the controller context.
self.content_type ||= Mime[:jsonapi]

renderer.render(resources, options, self).to_json
ActiveSupport::Notifications.instrument('render.jsonapi',
resources: resources,
options: options) do
renderer.render(resources, options, self).to_json
end
end
end
end
Expand Down