From d153dfe2cd5a21ea998ee8ab0a9191f819ec5bcf Mon Sep 17 00:00:00 2001 From: Kory Tegman Date: Wed, 6 Jan 2016 15:57:49 -0800 Subject: [PATCH 1/2] added documentation for adding custom root --- docs/general/rendering.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/general/rendering.md b/docs/general/rendering.md index 4350a719..550938ea 100644 --- a/docs/general/rendering.md +++ b/docs/general/rendering.md @@ -113,8 +113,25 @@ PR please :) #### root -PR please :) +By default the Json Adapter `root` will follow snake case format, like so: +| resource | single root | collection root | +|----------|-------------|-----------------| +| UserPost | user_posts | user_post | + +If you would like to change the `root` of your json, specify it in the render call: + +```ruby + render json: @user_post, root: "admin_post" +``` + +This will produce json like: +```json + {"admin_post": { + "title": "how to do open source" + } + } +``` #### serializer PR please :) From aeefb6a080ef0542ea195035762ed56b264b2fce Mon Sep 17 00:00:00 2001 From: Kory Tegman Date: Wed, 6 Jan 2016 22:21:19 -0800 Subject: [PATCH 2/2] revised docs to reflect the feedback --- docs/general/rendering.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/general/rendering.md b/docs/general/rendering.md index 550938ea..145958ed 100644 --- a/docs/general/rendering.md +++ b/docs/general/rendering.md @@ -113,25 +113,24 @@ PR please :) #### root -By default the Json Adapter `root` will follow snake case format, like so: +The resource root is derived from the class name of the resource being serialized. +e.g. `UserPostSerializer.new(UserPost.new)` will be serialized with the root `user_post` or `user_posts` according the adapter collection pluralization rules. -| resource | single root | collection root | -|----------|-------------|-----------------| -| UserPost | user_posts | user_post | - -If you would like to change the `root` of your json, specify it in the render call: +Specify the root by passing it as an argument to `render`. For example: ```ruby - render json: @user_post, root: "admin_post" + render json: @user_post, root: "admin_post", adapter: :json ``` -This will produce json like: +This will produce serialize as: ```json {"admin_post": { "title": "how to do open source" } } ``` +`Note: the Attributes adapter (default) does not include a resource root.` + #### serializer PR please :)