Merge pull request #2104 from cassidycodes/update-docs

Update Documentation on Serializers and Rendering [ci skip]
This commit is contained in:
Benjamin Fleischer 2017-04-30 22:06:10 -07:00 committed by GitHub
commit af5e9d6018
3 changed files with 37 additions and 7 deletions

View File

@ -10,6 +10,7 @@ Fixes:
Misc:
- [#2104](https://github.com/rails-api/active_model_serializers/pull/2104) Documentation for serializers and rendering. (@cassidycodes)
- [#2081](https://github.com/rails-api/active_model_serializers/pull/2081) Documentation for `include` option in adapters. (@charlie-wasp)
### [v0.10.5 (2017-03-07)](https://github.com/rails-api/active_model_serializers/compare/v0.10.4...v0.10.5)
@ -79,7 +80,7 @@ Misc:
- [#1878](https://github.com/rails-api/active_model_serializers/pull/1878) Cache key generation for serializers now uses `ActiveSupport::Cache.expand_cache_key` instead of `Array#join` by default and is also overridable. This change should be backward-compatible. (@markiz)
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka)
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@cassidycodes)
- [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli)
- [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono)
- [#1967](https://github.com/rails-api/active_model_serializers/pull/1967) Improve type method documentation. (@yukideluxe)

View File

@ -203,7 +203,7 @@ link(:link_name) { url_for(controller: 'controller_name', action: 'index', only_
#### include
PR please :)
See [Adapters: Include Option](/docs/general/adapters.md#include-option).
#### Overriding the root key
@ -260,15 +260,29 @@ Note that by using a string and symbol, Ruby will assume the namespace is define
#### serializer
PR please :)
Specify which serializer to use if you want to use a serializer other than the default.
For a single resource:
```ruby
@post = Post.first
render json: @post, serializer: SpecialPostSerializer
```
To specify which serializer to use on individual items in a collection (i.e., an `index` action), use `each_serializer`:
```ruby
@posts = Post.all
render json: @posts, each_serializer: SpecialPostSerializer
```
#### scope
PR please :)
See [Serializers: Scope](/docs/general/serializers.md#scope).
#### scope_name
PR please :)
See [Serializers: Scope](/docs/general/serializers.md#scope).
## Using a serializer without `render`

View File

@ -382,11 +382,26 @@ The serialized value for a given key. e.g. `read_attribute_for_serialization(:ti
#### #links
PR please :)
Allows you to modify the `links` node. By default, this node will be populated with the attributes set using the [::link](#link) method. Using `links: nil` will remove the `links` node.
```ruby
ActiveModelSerializers::SerializableResource.new(
@post,
adapter: :json_api,
links: {
self: {
href: 'http://example.com/posts',
meta: {
stuff: 'value'
}
}
}
)
```
#### #json_key
PR please :)
Returns the key used by the adapter as the resource root. See [root](#root) for more information.
## Examples