Merge pull request #1280 from vasilakisfil/patch-1

Show how pagination can be done using meta tag from controller in JSON adapter
This commit is contained in:
L. Preston Sego III 2016-03-10 12:53:41 -05:00
commit bbebeab348

View File

@ -114,6 +114,26 @@ ex.
}
```
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.
```ruby
render json: @posts, each_serializer: PostPreviewSerializer, meta: meta_attributes(@post)
```
```ruby
#expects pagination!
def meta_attributes(resource, extra_meta = {})
{
current_page: resource.current_page,
next_page: resource.next_page,
prev_page: resource.prev_page,
total_pages: resource.total_pages,
total_count: resource.total_count
}.merge(extra_meta)
end
```
### Attributes adapter
This adapter does not allow us to use `meta` key, due to that it is not possible to add pagination links.