Skip to content

Add note clarifying context hash usage when passing resources through the ResourceSerializer#821

Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
kevinzwhuang:serializer-context-note
Sep 12, 2016
Merged

Add note clarifying context hash usage when passing resources through the ResourceSerializer#821
lgebhardt merged 1 commit intoJSONAPI-Resources:masterfrom
kevinzwhuang:serializer-context-note

Conversation

@kevinzwhuang
Copy link
Copy Markdown
Contributor

Description:
I found the documentation to be lacking in explaining how context is passed in when using the ResourceSerializer.

Only after playing around with the ResourceSerializer for some time that I found that the second argument for initializing a resource was the context itself. In the documentation, this second argument was simply nil without explanation that this was actually the context the resource initializes with:
JSONAPI::ResourceSerializer.new(PostResource).serialize_to_hash(PostResource.new(post, nil))

Changes Proposed:

  • Add a note clarifying how to pass in a context hash when using the ResourceSerializer.
  • Add a code example that shows how it works, building on top of the first example, which leads into the results in the ResourceSerializer section below it.

Hopefully this will help newcomers who might need context for their resource while using ResourceSerializers. Hope this helps @lgebhardt!

@lgebhardt lgebhardt merged commit 33dc8dd into JSONAPI-Resources:master Sep 12, 2016
@lgebhardt
Copy link
Copy Markdown
Contributor

@kevinzwh Thanks!

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.

2 participants