include query_parameters on pagination links as well

This commit is contained in:
Bruno Bacarini
2015-08-10 12:26:16 -03:00
parent e62a7d6f34
commit 7be25fef14
6 changed files with 71 additions and 44 deletions

View File

@@ -14,17 +14,14 @@ module ActiveModel
end
def page_links
build_links
pages_from.each_with_object({}) do |(key, value), hash|
params = query_parameters.merge(page: { number: value, size: collection.size }).to_query
hash[key] = "#{url}?#{params}"
end
end
private
def build_links
pages_from.each_with_object({}) do |(key, value), hash|
hash[key] = "#{url}?page=#{value}&per_page=#{collection.size}"
end
end
def pages_from
return {} if collection.total_pages == FIRST_PAGE
@@ -55,6 +52,10 @@ module ActiveModel
def default_url
options[:original_url]
end
def query_parameters
options[:query_parameters] ? options[:query_parameters] : {}
end
end
end
end