From acb6545c508b931d90df2382bf13595692b401a0 Mon Sep 17 00:00:00 2001 From: Bruno Bacarini Date: Sat, 8 Aug 2015 16:25:22 -0300 Subject: [PATCH] add documentation to pagination feature --- README.md | 12 --------- docs/README.md | 1 + docs/howto/add_pagination_links.md | 39 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 docs/howto/add_pagination_links.md diff --git a/README.md b/README.md index 45361ea8..15e86947 100644 --- a/README.md +++ b/README.md @@ -273,18 +273,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. diff --git a/docs/README.md b/docs/README.md index ddecb3e4..2398528b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 diff --git a/docs/howto/add_pagination_links.md b/docs/howto/add_pagination_links.md new file mode 100644 index 00000000..0445903d --- /dev/null +++ b/docs/howto/add_pagination_links.md @@ -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" + } +} +```