File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change 1
1
# api-pagination [ ![ Build Status] ( https://travis-ci.org/davidcelis/api-pagination.png )] ( https://travis-ci.org/davidcelis/api-pagination )
2
2
3
- Put pagination info for your Rails API in your Link headers, not your response body.
3
+ Put pagination info for your API in Link headers, not the response body.
4
4
5
5
## Installation
6
6
Original file line number Diff line number Diff line change 4
4
module ApiPagination
5
5
protected
6
6
def paginate ( scope )
7
- query_params = request . query_parameters
8
- scope = instance_variable_get ( :"@#{ scope } " )
9
- url = request . original_url . sub ( /\? .*$/ , '' )
10
- pages = { }
11
- links = [ ]
7
+ scope = instance_variable_get ( :"@#{ scope } " )
8
+ url = request . original_url . sub ( /\? .*$/ , '' )
9
+ pages = { }
12
10
13
11
unless scope . first_page?
14
12
pages [ :first ] = 1
@@ -20,9 +18,9 @@ def paginate(scope)
20
18
pages [ :next ] = scope . current_page + 1
21
19
end
22
20
23
- pages . each do |k , v |
24
- new_params = query_params . merge ( { :page => v } )
25
- links << %(<#{ url } ?#{ new_params . to_param } >; rel="#{ k } ")
21
+ links = pages . map do |k , v |
22
+ new_params = request . query_parameters . merge ( { :page => v } )
23
+ %(<#{ url } ?#{ new_params . to_param } >; rel="#{ k } ")
26
24
end
27
25
28
26
headers [ 'Link' ] = links . join ( ', ' )
You can’t perform that action at this time.
0 commit comments