mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Update README.md
This commit is contained in:
parent
5504293776
commit
358b6a8875
18
README.md
18
README.md
@ -141,10 +141,14 @@ render :json => @posts, :root => "some_posts"
|
||||
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 4 options:
|
||||
|
||||
#### 1. Disable root globally for in `ArraySerializer`. In an initializer:
|
||||
#### 1. Disable root globally for `ArraySerializer`. In an initializer:
|
||||
|
||||
```ruby
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
# Disabled for all serializers
|
||||
# ActiveModel::Serializer.root = false
|
||||
|
||||
# Or just for the ArraySerializer
|
||||
ActiveModel::ArraySerializer.root = false
|
||||
end
|
||||
```
|
||||
@ -195,18 +199,6 @@ def default_serializer_options
|
||||
end
|
||||
```
|
||||
|
||||
## Disabling root globally
|
||||
|
||||
If you want to disable the ```root```-node for all serializers, not just when
|
||||
they are used in ```respond_with```, you can set the ```root``` option for the
|
||||
main class in an initializer just like with Arrays:
|
||||
|
||||
```ruby
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
ActiveModel::Serializer.root = false
|
||||
end
|
||||
```
|
||||
|
||||
## Getting the old version
|
||||
|
||||
If you find that your project is already relying on the old rails to_json
|
||||
|
||||
Loading…
Reference in New Issue
Block a user