mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
@@ -23,7 +23,6 @@ This is the documentation of ActiveModelSerializers, it's focused on the **0.10.
|
||||
- [How to add pagination links](howto/add_pagination_links.md)
|
||||
- [Using ActiveModelSerializers Outside Of Controllers](howto/outside_controller_use.md)
|
||||
- [Testing ActiveModelSerializers](howto/test.md)
|
||||
- [How to add top-level links](howto/add_top_level_links.md) (```JSON-API``` only)
|
||||
|
||||
## Integrations
|
||||
|
||||
|
||||
@@ -103,7 +103,46 @@ PR please :)
|
||||
|
||||
#### links
|
||||
|
||||
PR please :)
|
||||
##### How to add top-level links
|
||||
|
||||
JsonApi supports a [links object](http://jsonapi.org/format/#document-links) to be specified at top-level, that you can specify in the `render`:
|
||||
|
||||
```ruby
|
||||
links_object = {
|
||||
href: "http://example.com/api/posts",
|
||||
meta: {
|
||||
count: 10
|
||||
}
|
||||
}
|
||||
render json: @posts, links: links_object
|
||||
```
|
||||
|
||||
That's the result:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"type": "posts",
|
||||
"id": "1",
|
||||
"attributes": {
|
||||
"title": "JSON API is awesome!",
|
||||
"body": "You should be using JSON API",
|
||||
"created": "2015-05-22T14:56:29.000Z",
|
||||
"updated": "2015-05-22T14:56:28.000Z"
|
||||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"href": "http://example.com/api/posts",
|
||||
"meta": {
|
||||
"count": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This feature is specific to JsonApi, so you have to use the use the [JsonApi Adapter](adapters.md#jsonapi)
|
||||
|
||||
### serializer_opts
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
# How to add top-level links
|
||||
|
||||
JsonApi supports a [links object](http://jsonapi.org/format/#document-links) to be specified at top-level, that you can specify in the `render`:
|
||||
|
||||
```ruby
|
||||
links_object = {
|
||||
href: "http://example.com/api/posts",
|
||||
meta: {
|
||||
count: 10
|
||||
}
|
||||
}
|
||||
render json: @posts, links: links_object
|
||||
```
|
||||
|
||||
That's the result:
|
||||
|
||||
```json
|
||||
{
|
||||
"data": [
|
||||
{
|
||||
"type": "posts",
|
||||
"id": "1",
|
||||
"attributes": {
|
||||
"title": "JSON API is awesome!",
|
||||
"body": "You should be using JSON API",
|
||||
"created": "2015-05-22T14:56:29.000Z",
|
||||
"updated": "2015-05-22T14:56:28.000Z"
|
||||
}
|
||||
}
|
||||
],
|
||||
"links": {
|
||||
"href": "http://example.com/api/posts",
|
||||
"meta": {
|
||||
"count": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This feature is specific to JsonApi, so you have to use the use the [JsonApi Adapter](https://github.com/rails-api/active_model_serializers/blob/master/docs/general/adapters.md#jsonapi)
|
||||
Reference in New Issue
Block a user