Skip to content

Commit e3d1668

Browse files
committed
Move docs from README to docs/ dir
1 parent 1dcb3b3 commit e3d1668

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ render json: @post, meta: { total: 10 }, meta_key: "custom_meta"
138138

139139
`meta` will only be included in your response if you are using an Adapter that supports `root`, as JsonAPI and Json adapters, the default adapter (FlattenJson) doesn't have `root`.
140140

141-
### Links
142-
143-
A top-level `links` object may be specified in the `render` call:
144-
145-
```ruby
146-
render json: @post, links: { self: "/posts/1" }
147-
```
148-
149141
### Overriding association methods
150142

151143
If you want to override any association, you can use:

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
1212
## How to
1313

1414
- [How to add root key](howto/add_root_key.md)
15+
- [How to add top-level links](howto/add_top_level_links.md) (```JSON-API``` only)
1516

1617
## Getting Help
1718

docs/howto/add_top_level_links.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# How to add top-level links
2+
3+
JsonApi supports a [links object](http://jsonapi.org/format/#document-links) to be specified at top-level, that you can specify in the `render`:
4+
5+
```ruby
6+
render json: @posts, links: { "self": "http://example.com/api/posts" }
7+
```
8+
9+
That's the result:
10+
11+
```json
12+
{
13+
"data": [
14+
{
15+
"type": "posts",
16+
"id": "1",
17+
"attributes": {
18+
"title": "JSON API is awesome!",
19+
"body": "You should be using JSON API",
20+
"created": "2015-05-22T14:56:29.000Z",
21+
"updated": "2015-05-22T14:56:28.000Z"
22+
}
23+
}
24+
],
25+
"links": {
26+
"self": "http://example.com/api/posts"
27+
}
28+
}
29+
```
30+
31+
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)

test/action_controller/serialization_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def render_array_using_implicit_serializer_and_links
6565
Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
6666
]
6767

68-
render json: @profiles, links: { self: "/profiles/1" }
68+
render json: @profiles, links: { self: "http://example.com/api/profiles/1" }
6969
end
7070
end
7171

@@ -292,7 +292,7 @@ def test_render_array_using_implicit_serializer_and_links
292292
}
293293
],
294294
links: {
295-
self: "/profiles/1"
295+
self: "http://example.com/api/profiles/1"
296296
}
297297
}
298298

0 commit comments

Comments
 (0)