Skip to content

Commit b73ffe2

Browse files
committed
add kaminari and will_paginate examples
1 parent 3c3578a commit b73ffe2

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

docs/howto/add_pagination_links.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ Pagination links will be included in your response automatically as long as the
66

77
If you want pagination links in your response, use [Kaminari](https://github.com/amatsuda/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
88

9+
###### Kaminari examples
910
```ruby
10-
#kaminari example
11-
@posts = Kaminari.paginate_array(Post.all).page(3).per(1)
11+
#array
12+
@posts = Kaminari.paginate_array([1, 2, 3]).page(3).per(1)
1213
render json: @posts
1314

14-
#will_paginate example
15-
@posts = Post.all.paginate(page: 3, per_page: 1)
15+
#active_record
16+
@posts = Post.page(3).per(1)
17+
render json: @posts
18+
```
19+
20+
###### WillPaginate examples
21+
22+
```ruby
23+
#array
24+
@posts = [1,2,3].paginate(page: 3, per_page: 1)
25+
render json: @posts
26+
27+
#active_record
28+
@posts = Post.page(3).per_page(1)
1629
render json: @posts
1730
```
1831

@@ -45,7 +58,8 @@ ex:
4558
}
4659
```
4760

48-
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.
61+
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).
62+
4963

5064
### JSON adapter
5165

0 commit comments

Comments
 (0)