mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user