Support serializer and each_serializer in render json

This commit is contained in:
Gary Gordon
2014-10-27 10:44:21 -04:00
parent 95d122046d
commit c84430cdad
5 changed files with 100 additions and 7 deletions

View File

@@ -94,6 +94,22 @@ member when the resource names are included in the `include` option.
render @posts, include: 'authors,comments'
```
### Specify a serializer
If you wish to use a serializer other than the default, you can explicitly pass it to the renderer.
#### 1. For a resource:
```ruby
render json: @post, serializer: PostPreviewSerializer
```
#### 2. For an array resource:
```ruby
render json: @posts, serializer: PaginatedSerializer, each_serializer: PostPreviewSerializer
```
## Installation
Add this line to your application's Gemfile: