Merge branch 'master' into domitian-move-namespace-of-adapter-to-active-model-serializers

Conflicts:
	CHANGELOG.md
	lib/active_model/serializer/adapter/attributes.rb
	lib/active_model/serializer/adapter/cached_serializer.rb
	lib/active_model/serializer/adapter/fragment_cache.rb
	lib/active_model/serializer/adapter/json_api.rb
	lib/active_model/serializer/adapter/json_api/link.rb
	test/adapter/fragment_cache_test.rb
	test/adapter/json_api/links_test.rb
	test/adapter/json_api/resource_type_config_test.rb
This commit is contained in:
Benjamin Fleischer
2016-02-23 23:21:49 -06:00
39 changed files with 1357 additions and 341 deletions

View File

@@ -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

View File

@@ -107,12 +107,30 @@ end
#### ::type
e.g.
The `::type` method defines the JSONAPI [type](http://jsonapi.org/format/#document-resource-object-identification) that will be rendered for this serializer.
It either takes a `String` or `Symbol` as parameter.
Note: This method is useful only when using the `:json_api` adapter.
Examples:
```ruby
class UserProfileSerializer < ActiveModel::Serializer
type 'profile'
end
class AuthorProfileSerializer < ActiveModel::Serializer
type :profile
end
```
With the `:json_api` adapter, the previous serializers would be rendered as:
``` json
{
"data": {
"id": "1",
"type": "profile"
}
}
```
#### ::link