Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/metadata on jsonapi render #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

idlechara
Copy link

Currently there is no way to pass top-level meta objects in the current implementation as it only filters for pagination options, record_count and page_count.

This line allows to jsonapi_render to include top-level meta information in the following way:

jsonapi_render json: MyResource.first, status: :ok, options: { meta: { author: "Erik Regla", pls_approve_dis: "true" } } 

@npendery
Copy link

Any hold up on this change. It would be very useful!

@@ -186,6 +186,8 @@ def turn_into_resource(record, options)
# @api private
def result_options(records, options)
{}.tap do |data|
data[:meta] = options.fetch(:meta, {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if data[:meta] has record counts already, but id maybe merge the two instead of assigning

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data[:meta] = options.fetch(:meta, {})
data[:meta] = data.fetch(:meta, {}).merge(options.fetch(:meta, {}))

@kceb
Copy link

kceb commented Aug 19, 2021

@tiagopog could we add this? It would be very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants