Skip to content

Commit

Permalink
Add warnings about global adapter config to docs (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpinsky authored and bf4 committed Oct 24, 2017
1 parent 4d7c245 commit 88367da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Fixes:

Misc:

- #2176 Documentation for global adapter config (@mrpinsky)

### [v0.10.6 (2017-05-01)](https://github.com/rails-api/active_model_serializers/compare/v0.10.5...v0.10.6)

Fixes:
Expand Down
6 changes: 6 additions & 0 deletions docs/general/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ The `Attributes` adapter does not include a root key. It is just the serialized

Use either the `JSON` or `JSON API` adapters if you want the response document to have a root key.

***IMPORTANT***: Adapter configuration has *no effect* on a serializer instance
being used directly. That is, `UserSerializer.new(user).as_json` will *always*
behave as if the adapter were the 'Attributes' adapter. See [Outside Controller
Usage](../howto/outside_controller_use.md) for more details on recommended
usage.

## Built in Adapters

### Attributes - Default
Expand Down
7 changes: 7 additions & 0 deletions docs/howto/add_root_key.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ In order to add the root key you need to use the ```JSON``` Adapter, you can cha
ActiveModelSerializers.config.adapter = :json
```

Note that adapter configuration has no effect on a serializer that is called
directly, e.g. in a serializer unit test. Instead, something like
`UserSerializer.new(user).as_json` will *always* behave as if the adapter were
the 'Attributes' adapter. See [Outside Controller
Usage](../howto/outside_controller_use.md) for more details on recommended
usage.

You can also specify a class as adapter, as long as it complies with the ActiveModelSerializers adapters interface.
It will add the root key to all your serialized endpoints.

Expand Down

0 comments on commit 88367da

Please sign in to comment.