Skip to content

Commit b9e0776

Browse files
committed
Simplification for later.
Signed-off-by: David Celis <[email protected]>
1 parent 9498645 commit b9e0776

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

lib/api-pagination.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
module 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(', ')

0 commit comments

Comments
 (0)