mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Updating the meta key documentation to warn users that { root: false } will cause the serializer to ignore the meta key as it leads to invalid JSON.
https://github.com/rails-api/active_model_serializers/issues/332
This commit is contained in:
parent
4f185efa90
commit
b20ad33407
11
README.md
11
README.md
@ -1,4 +1,4 @@
|
||||
[](https://travis-ci.org/rails-api/active_model_serializers) [](https://codeclimate.com/github/rails-api/active_model_serializers) [](https://coveralls.io/r/rails-api/active_model_serializers)
|
||||
[](https://travis-ci.org/rails-api/active_model_serializers) [](https://codeclimate.com/github/rails-api/active_model_serializers) [](https://coveralls.io/r/rails-api/active_model_serializers)
|
||||
|
||||
# Purpose
|
||||
|
||||
@ -13,7 +13,7 @@ content.
|
||||
In short, **serializers replace hash-driven development with object-oriented
|
||||
development.**
|
||||
|
||||
# Installing
|
||||
# Installing
|
||||
|
||||
The easiest way to install `ActiveModel::Serializers` is to add it to your
|
||||
`Gemfile`:
|
||||
@ -28,7 +28,7 @@ Then, install it on the command line:
|
||||
$ bundle install
|
||||
```
|
||||
|
||||
#### Ruby 1.8 is no longer supported!
|
||||
#### Ruby 1.8 is no longer supported!
|
||||
|
||||
If you must use a ruby 1.8 version (MRI 1.8.7, REE, Rubinius 1.8, or JRuby 1.8), you need to use version 0.8.x.
|
||||
Versions after 0.9.0 do not support ruby 1.8. To specify version 0.8, include this in your Gemfile:
|
||||
@ -177,7 +177,7 @@ In an initializer:
|
||||
ActiveSupport.on_load(:active_model_serializers) do
|
||||
# Disable for all serializers (except ArraySerializer)
|
||||
ActiveModel::Serializer.root = false
|
||||
|
||||
|
||||
# Disable for ArraySerializer
|
||||
ActiveModel::ArraySerializer.root = false
|
||||
end
|
||||
@ -351,6 +351,9 @@ The above usage of `:meta_key` will produce the following:
|
||||
}
|
||||
```
|
||||
|
||||
When using meta information, your serializer cannot have the `{ root: false }` option, as this would lead to
|
||||
invalid JSON. If you do not have a root key, the meta information will be ignored.
|
||||
|
||||
If you would like direct, low-level control of attribute serialization, you can
|
||||
completely override the `attributes` method to return the hash you need:
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user