File tree Expand file tree Collapse file tree 4 files changed +12
-7
lines changed
lib/active_model/serializer Expand file tree Collapse file tree 4 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ AMS does this through two components: **serializers** and **adapters**.
8
8
Serializers describe _ which_ attributes and relationships should be serialized.
9
9
Adapters describe _ how_ attributes and relationships should be serialized.
10
10
11
+ By default AMS will use the JsonApi Adapter that follows RC3 of the format specified in [ jsonapi.org/format] ( http://jsonapi.org/format ) .
12
+ Check how to change the adapter in the sections bellow.
13
+
11
14
# RELEASE CANDIDATE, PLEASE READ
12
15
13
16
This is the master branch of AMS. It will become the ` 0.10.0 ` release when it's
47
50
```
48
51
49
52
Generally speaking, you as a user of AMS will write (or generate) these
50
- serializer classes. If you want to use a different adapter, such as a JsonApi, you can
53
+ serializer classes. If you want to use a different adapter, such as a normal Json adapter without the JsonApi conventions , you can
51
54
change this in an initializer:
52
55
53
56
``` ruby
54
- ActiveModel ::Serializer .config.adapter = ActiveModel ::Serializer ::Adapter ::JsonApi
57
+ ActiveModel ::Serializer .config.adapter = ActiveModel ::Serializer ::Adapter ::Json
55
58
```
56
59
57
60
or
58
61
59
62
``` ruby
60
- ActiveModel ::Serializer .config.adapter = :json_api
63
+ ActiveModel ::Serializer .config.adapter = :json
61
64
```
62
65
63
66
You won't need to implement an adapter unless you wish to use a new format or
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ module Configuration
6
6
7
7
included do |base |
8
8
base . config . array_serializer = ActiveModel ::Serializer ::ArraySerializer
9
- base . config . adapter = :json
9
+ base . config . adapter = :json_api
10
10
end
11
11
end
12
12
end
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ module ActionController
4
4
module Serialization
5
5
class AdapterSelectorTest < ActionController ::TestCase
6
6
class MyController < ActionController ::Base
7
- def render_using_default_adapter
7
+ def render_using_the_initializer_defined_adapter
8
8
@profile = Profile . new ( { name : 'Name 1' , description : 'Description 1' , comments : 'Comments 1' } )
9
9
render json : @profile
10
10
end
@@ -23,7 +23,7 @@ def render_skipping_adapter
23
23
tests MyController
24
24
25
25
def test_render_using_default_adapter
26
- get :render_using_default_adapter
26
+ get :render_using_the_initializer_defined_adapter
27
27
assert_equal '{"name":"Name 1","description":"Description 1"}' , response . body
28
28
end
29
29
Original file line number Diff line number Diff line change
1
+ ActiveModel ::Serializer . config . adapter = :json
2
+
1
3
class Model
2
4
def initialize ( hash = { } )
3
5
@attributes = hash
@@ -64,7 +66,7 @@ class ProfilePreviewSerializer < ActiveModel::Serializer
64
66
Bio = Class . new ( Model )
65
67
Blog = Class . new ( Model )
66
68
Role = Class . new ( Model )
67
- User = Class . new ( Model )
69
+ User = Class . new ( Model )
68
70
Location = Class . new ( Model )
69
71
Place = Class . new ( Model )
70
72
You can’t perform that action at this time.
0 commit comments