mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Update Serializers and Rendering Docs
- Updating general/serializers.md - Updating docs/general/rendering.md - adding to changelog - Updating rendering.md to indicate that `each_serializer` must be used on a collection - updating my handle in previous changelog entry
This commit is contained in:
parent
f5ad632cc0
commit
aa619b5e0e
@ -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)
|
||||
|
||||
@ -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`
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user