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

Add resource-level meta docs. Update top-level meta docs. #1566

Merged
merged 1 commit into from
Mar 11, 2016
Merged
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
37 changes: 31 additions & 6 deletions docs/general/rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ PR please :)

#### meta

If you want a `meta` attribute in your response, specify it in the `render`
call:
A `meta` member can be used to include non-standard meta-information. `meta` can
Copy link
Member

Choose a reason for hiding this comment

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

s/non-standard/custom (or something to that effect)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, although that's copy from the JSON API docs.

Copy link
Member

Choose a reason for hiding this comment

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

You're right. I saw that later :embarrassed:

On Wed, Mar 9, 2016 at 8:40 AM Ben Mills notifications@github.com wrote:

In docs/general/rendering.md
#1566 (comment)
:

@@ -81,8 +81,12 @@ PR please :)

meta

-If you want a meta attribute in your response, specify it in the render
-call:
+A meta member can be used to include non-standard meta-information. meta can

Sure, although that's copy from the JSON API docs.


Reply to this email directly or view it on GitHub
https://github.com/rails-api/active_model_serializers/pull/1566/files#r55526872
.

be utilized in several levels in a response.
Copy link
Member

Choose a reason for hiding this comment

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

utilized vs. used, go!

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you saying you'd like this changed to used?


##### Top-level

To set top-level `meta` in a response, specify it in the `render` call.

```ruby
render json: @post, meta: { total: 10 }
Expand All @@ -94,12 +98,33 @@ The key can be customized using `meta_key` option.
render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
```

`meta` will only be included in your response if you are using an Adapter that supports `root`,
as JsonAPI and Json adapters, the default adapter (Attributes) doesn't have `root`.
`meta` will only be included in your response if you are using an Adapter that
supports `root`, e.g., `JsonApi` and `Json` adapters. The default adapter,
`Attributes` does not have `root`.
Copy link
Member

Choose a reason for hiding this comment

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

Might want to collaborate with #1557 in some way

Copy link
Member Author

Choose a reason for hiding this comment

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

My plan was to make minimal changes here so #1557 still has things that can be done.


#### meta_key

PR please :)
##### Resource-level

To set resource-level `meta` in a response, define meta in a serializer with one
of the following methods:

As a single, static string.

```ruby
meta stuff: 'value'
```

As a block containing a Hash.

```ruby
meta do
{
rating: 4,
comments_count: object.comments.count
}
end
```

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there something specific you're directing my attention here to do?


#### links

Expand Down