From 4219844c12c335ebcb5b62d94ff41dda2312ba7f Mon Sep 17 00:00:00 2001 From: Ben Mills Date: Tue, 8 Mar 2016 20:47:22 -0700 Subject: [PATCH] Add resource-level meta docs. Update top-level meta docs. --- docs/general/rendering.md | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/docs/general/rendering.md b/docs/general/rendering.md index 0f79321f..28fdaa36 100644 --- a/docs/general/rendering.md +++ b/docs/general/rendering.md @@ -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 +be utilized in several levels in a response. + +##### Top-level + +To set top-level `meta` in a response, specify it in the `render` call. ```ruby render json: @post, meta: { total: 10 } @@ -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`. -#### 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 +``` + #### links