mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
cleanup markdown in docs
This commit is contained in:
@@ -72,7 +72,7 @@ serializer and available as `@options` inside.
|
||||
|
||||
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
|
||||
class Post < ActiveRecord::Base
|
||||
@@ -82,7 +82,7 @@ To specify a custom serializer for an object, there are 2 options:
|
||||
end
|
||||
```
|
||||
|
||||
2. Specify the serializer when you render the object:
|
||||
#### 2. Specify the serializer when you render the object:
|
||||
|
||||
```ruby
|
||||
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
|
||||
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
|
||||
ActiveModel::ArraySerializer.root = false
|
||||
```
|
||||
|
||||
2. Disable root per render call in your controller:
|
||||
#### 2. Disable root per render call in your controller:
|
||||
|
||||
```ruby
|
||||
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
|
||||
class CustomArraySerializer < ActiveModel::ArraySerializer
|
||||
|
||||
Reference in New Issue
Block a user