From b4cd4cd5baa580fbdcea129a66bc279f5b445bb7 Mon Sep 17 00:00:00 2001 From: Billy Date: Thu, 23 Jan 2014 11:46:07 +0800 Subject: [PATCH] add doc for use serailizer independently --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 6bd614eb..b6401ec8 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,20 @@ To specify a custom serializer for the items within an array: render json: @posts, each_serializer: FancyPostSerializer ``` +## Render independently + +By default the setting of serializer is in controller as described above which is the +recommeneded way. However, there may be cases you need to render the json object elsewhere +say in a helper or a view when controller is only for main object. + +Then you can render the serialized JSON independently. + +```ruby +def current_user_as_json_helper + CurrentUserSerializer.new(current_user).to_json +end +``` + ## Disabling the root element You have 4 options to disable the root element, each with a slightly different scope: