You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[#1839](https://github.com/rails-api/active_model_serializers/pull/1839)`fields` tests demonstrating usage for both attributes and relationships. (@NullVoxPopuli)
Copy file name to clipboardExpand all lines: docs/howto/add_link.md
+22-23
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,20 @@
4
4
5
5
`ActiveModelSerializers` offers you many ways to add links in your JSON reponse depending on the adapter you are using.
6
6
7
+
Note that within the following examples, we set the `adapter` option, but that is not needed if the `ActiveModelSerializers.config.adapter` variable is properly set. Also, some examples are given for both Rails and [non-Rails usage](outside_controller_use.md).
8
+
9
+
Unless stated otherwise, the examples given here will assume that the following classes are defined:
10
+
11
+
```ruby
12
+
classUser < ActiveModelSerializers::Model
13
+
attributes :id, :name
14
+
end
15
+
16
+
classUserSerializer < ActiveModel::Serializer
17
+
attributes :id, :name
18
+
end
19
+
```
20
+
7
21
## JSON API adapter
8
22
9
23
The JSON API specification allows the usage of the `links` member for representing links in three cases:
@@ -18,19 +32,9 @@ The JSON API specification allows the usage of the `links` member for representi
18
32
In order to provide top-level links, you will need to specify the `links` option to the serialization:
`ActiveModelSerializers` will provides automatic pagination links for collections if use [Kaminari](https://github.com/amatsuda/kaminari)
71
-
or [WillPaginate](https://github.com/mislav/will_paginate):
72
+
`ActiveModelSerializers` will provide automatic pagination links for collections if you use [Kaminari](https://github.com/amatsuda/kaminari)
73
+
or [WillPaginate](https://github.com/mislav/will_paginate) and the `ActiveModelSerializers.config.jsonapi_pagination_links_enabled` config is set to `true` (defaults to `true`). To disable this feature, you can simply set this config to `false`.
72
74
73
75
```ruby
74
76
classUserController < ActionController::Base
@@ -108,15 +110,15 @@ Any of these actions would result in:
108
110
}
109
111
```
110
112
111
-
Note that `ActiveModelSerializers` pagination relies on a collection that has the methods `current_page`, `total_pages`, and `size`, such as are supported by both [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). If you want to have paginated links your collections but don't want to use neither Kaminari nor WillPaginate, make sure to define these methods.
113
+
Note that it is possible to opt-out `ActiveModelSerializers` pagination relies on a collection that has the methods `current_page`, `total_pages`, and `size`, such as are supported by both [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). If you want to have paginated links your collections but don't want to use neither Kaminari nor WillPaginate, make sure to define these methods.
0 commit comments