Skip to content

Commit

Permalink
add documentation to pagination feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bacarini committed Aug 8, 2015
1 parent b508abd commit db8ae19
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ActiveModel::Serializer


[![Build Status](https://travis-ci.org/rails-api/active_model_serializers.svg)](https://travis-ci.org/rails-api/active_model_serializers)

ActiveModel::Serializer brings convention over configuration to your JSON generation.
Expand Down Expand Up @@ -273,18 +274,6 @@ And you can change the JSON key that the serializer should use for a particular
The `url` declaration describes which named routes to use while generating URLs
for your JSON. Not every adapter will require URLs.

## Pagination

If you want pagination links in your response, specify it in the `render`

```ruby
render json: @posts, pagination: true
```

AMS relies on either Kaminari or WillPaginate. Please install either dependency by adding one of those to your Gemfile.

Pagination links will only be included in your response if you are using a JsonAPI adapter, the others adapters doesn't have this feature.

## Caching

To cache a serializer, call ```cache``` and pass its options.
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This is the documentation of AMS, it's focused on the **0.10.x version.**
## How to

- [How to add root key](howto/add_root_key.md)
- [How to add pagination links](howto/add_pagination_links.md) (```JSON-API``` only)

## Getting Help

Expand Down
39 changes: 39 additions & 0 deletions docs/howto/add_pagination_links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# How to add pagination links

If you want pagination links in your response, specify it in the `render`

```ruby
render json: @posts, pagination: true
```

AMS relies on either `Kaminari` or `WillPaginate`. Please install either dependency by adding one of those to your Gemfile.

Pagination links will only be included in your response if you are using a ```JSON-API``` adapter, the others adapters doesn't have this feature.

```ruby
ActiveModel::Serializer.config.adapter = :json_api
```

ex:
```json
{
"data": [
{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
}
}
],
"links": {
"first": "?page=1&per_page=1",
"prev": "?page=2&per_page=1",
"next": "?page=4&per_page=1",
"last": "?page=13&per_page=1"
}
}
```

0 comments on commit db8ae19

Please sign in to comment.