Skip to content

Commit 91d6215

Browse files
committed
Update add_pagination_links.md
1 parent b2cd7bb commit 91d6215

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/howto/add_pagination_links.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ ex.
110110
}
111111
```
112112

113+
You can also achieve the same result if you have a helper method that adds the pagination info in the meta tag. For instance, in your action specify a custom serializer.
114+
115+
```ruby
116+
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
117+
```
118+
119+
```ruby
120+
#expects pagination!
121+
def meta_attributes(resource, extra_meta = {})
122+
{
123+
current_page: resource.current_page,
124+
next_page: resource.next_page,
125+
prev_page: resource.prev_page,
126+
total_pages: resource.total_pages,
127+
total_count: resource.total_count
128+
}.merge(extra_meta)
129+
end
130+
```
131+
132+
113133
### Attributes adapter
114134

115135
This adapter does not allow us to use `meta` key, due to that it is not possible to add pagination links.

0 commit comments

Comments
 (0)