Skip to content

Commit af5e9d6

Browse files
authored
Merge pull request #2104 from cassidycodes/update-docs
Update Documentation on Serializers and Rendering [ci skip]
2 parents 05cf222 + aa619b5 commit af5e9d6

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Fixes:
1010

1111
Misc:
1212

13+
- [#2104](https://github.com/rails-api/active_model_serializers/pull/2104) Documentation for serializers and rendering. (@cassidycodes)
1314
- [#2081](https://github.com/rails-api/active_model_serializers/pull/2081) Documentation for `include` option in adapters. (@charlie-wasp)
1415

1516
### [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:
7980

8081
- [#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)
8182

82-
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@ScottKbka)
83+
- [#1799](https://github.com/rails-api/active_model_serializers/pull/1799) Add documentation for setting the adapter. (@cassidycodes)
8384
- [#1909](https://github.com/rails-api/active_model_serializers/pull/1909) Add documentation for relationship links. (@vasilakisfil, @NullVoxPopuli)
8485
- [#1959](https://github.com/rails-api/active_model_serializers/pull/1959) Add documentation for root. (@shunsuke227ono)
8586
- [#1967](https://github.com/rails-api/active_model_serializers/pull/1967) Improve type method documentation. (@yukideluxe)

docs/general/rendering.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ link(:link_name) { url_for(controller: 'controller_name', action: 'index', only_
203203

204204
#### include
205205

206-
PR please :)
206+
See [Adapters: Include Option](/docs/general/adapters.md#include-option).
207207

208208
#### Overriding the root key
209209

@@ -260,15 +260,29 @@ Note that by using a string and symbol, Ruby will assume the namespace is define
260260

261261
#### serializer
262262

263-
PR please :)
263+
Specify which serializer to use if you want to use a serializer other than the default.
264+
265+
For a single resource:
266+
267+
```ruby
268+
@post = Post.first
269+
render json: @post, serializer: SpecialPostSerializer
270+
```
271+
272+
To specify which serializer to use on individual items in a collection (i.e., an `index` action), use `each_serializer`:
273+
274+
```ruby
275+
@posts = Post.all
276+
render json: @posts, each_serializer: SpecialPostSerializer
277+
```
264278

265279
#### scope
266280

267-
PR please :)
281+
See [Serializers: Scope](/docs/general/serializers.md#scope).
268282

269283
#### scope_name
270284

271-
PR please :)
285+
See [Serializers: Scope](/docs/general/serializers.md#scope).
272286

273287
## Using a serializer without `render`
274288

docs/general/serializers.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,26 @@ The serialized value for a given key. e.g. `read_attribute_for_serialization(:ti
382382

383383
#### #links
384384

385-
PR please :)
385+
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.
386+
387+
```ruby
388+
ActiveModelSerializers::SerializableResource.new(
389+
@post,
390+
adapter: :json_api,
391+
links: {
392+
self: {
393+
href: 'http://example.com/posts',
394+
meta: {
395+
stuff: 'value'
396+
}
397+
}
398+
}
399+
)
400+
```
386401

387402
#### #json_key
388403

389-
PR please :)
404+
Returns the key used by the adapter as the resource root. See [root](#root) for more information.
390405

391406
## Examples
392407

0 commit comments

Comments
 (0)