Skip to content

Commit bbebeab

Browse files
committed
Merge pull request #1280 from vasilakisfil/patch-1
Show how pagination can be done using meta tag from controller in JSON adapter
2 parents eb51506 + 91d6215 commit bbebeab

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
@@ -114,6 +114,26 @@ ex.
114114
}
115115
```
116116

117+
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.
118+
119+
```ruby
120+
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
121+
```
122+
123+
```ruby
124+
#expects pagination!
125+
def meta_attributes(resource, extra_meta = {})
126+
{
127+
current_page: resource.current_page,
128+
next_page: resource.next_page,
129+
prev_page: resource.prev_page,
130+
total_pages: resource.total_pages,
131+
total_count: resource.total_count
132+
}.merge(extra_meta)
133+
end
134+
```
135+
136+
117137
### Attributes adapter
118138

119139
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)