add kaminari and will_paginate examples

This commit is contained in:
Bruno Bacarini 2015-08-20 11:31:21 -03:00
parent 3c3578a9b8
commit b73ffe25c8

View File

@ -6,13 +6,26 @@ Pagination links will be included in your response automatically as long as the
If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
###### Kaminari examples
```ruby ```ruby
#kaminari example #array
@posts = Kaminari.paginate_array(Post.all).page(3).per(1) @posts = Kaminari.paginate_array([1, 2, 3]).page(3).per(1)
render json: @posts render json: @posts
#will_paginate example #active_record
@posts = Post.all.paginate(page: 3, per_page: 1) @posts = Post.page(3).per(1)
render json: @posts
```
###### WillPaginate examples
```ruby
#array
@posts = [1,2,3].paginate(page: 3, per_page: 1)
render json: @posts
#active_record
@posts = Post.page(3).per_page(1)
render json: @posts render json: @posts
``` ```
@ -45,7 +58,8 @@ ex:
} }
``` ```
AMS relies on either [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate). Please install either dependency by adding one of those to your Gemfile. AMS pagination relies on a paginated collection with the methods `current_page`, `total_pages`, and `size`, such as are supported by both [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
### JSON adapter ### JSON adapter