mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 23:06:50 +00:00
cleanup markdown in docs
This commit is contained in:
parent
53da0b12fd
commit
f8263153b6
@ -72,7 +72,7 @@ serializer and available as `@options` inside.
|
|||||||
|
|
||||||
To specify a custom serializer for an object, there are 2 options:
|
To specify a custom serializer for an object, there are 2 options:
|
||||||
|
|
||||||
1. Specify the serializer in your model:
|
#### 1. Specify the serializer in your model:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class Post < ActiveRecord::Base
|
class Post < ActiveRecord::Base
|
||||||
@ -82,7 +82,7 @@ To specify a custom serializer for an object, there are 2 options:
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Specify the serializer when you render the object:
|
#### 2. Specify the serializer when you render the object:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
render :json => @post, :serializer => FancyPostSerializer
|
render :json => @post, :serializer => FancyPostSerializer
|
||||||
@ -129,19 +129,19 @@ generates a root element "posts". To change it:
|
|||||||
You may disable the root element for arrays at the top level, which will result in
|
You may disable the root element for arrays at the top level, which will result in
|
||||||
more concise json. To disable the root element for arrays, you have 3 options:
|
more concise json. To disable the root element for arrays, you have 3 options:
|
||||||
|
|
||||||
1. Disable root globally for in ArraySerializer. In an initializer:
|
#### 1. Disable root globally for in ArraySerializer. In an initializer:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
ActiveModel::ArraySerializer.root = false
|
ActiveModel::ArraySerializer.root = false
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Disable root per render call in your controller:
|
#### 2. Disable root per render call in your controller:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
render :json => @posts, :root => false
|
render :json => @posts, :root => false
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Create a custom ArraySerializer and render arrays with it:
|
#### 3. Create a custom ArraySerializer and render arrays with it:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class CustomArraySerializer < ActiveModel::ArraySerializer
|
class CustomArraySerializer < ActiveModel::ArraySerializer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user