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 11# api-pagination [ ![ Build Status] ( https://travis-ci.org/davidcelis/api-pagination.png )] ( https://travis-ci.org/davidcelis/api-pagination )
22
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.
44
55## Installation
66
Original file line number Diff line number Diff line change 44module ApiPagination
55 protected
66 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 = { }
1210
1311 unless scope . first_page?
1412 pages [ :first ] = 1
@@ -20,9 +18,9 @@ def paginate(scope)
2018 pages [ :next ] = scope . current_page + 1
2119 end
2220
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 } ")
2624 end
2725
2826 headers [ 'Link' ] = links . join ( ', ' )
You can’t perform that action at this time.
0 commit comments