mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Add symbol support for ActiveModel::Serializer.type method
The ActiveModel::Serializer.type method now accepts symbol as paremeter: class AuthorSerializer < ActiveModel::Serializer type :profile end The test file for the type was also refactored.
This commit is contained in:
committed by
Yohan Robert
parent
f02f0849b1
commit
727d7631ae
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user