mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
include query_parameters on pagination links as well
This commit is contained in:
@@ -25,7 +25,10 @@ module ActionController
|
||||
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource#serialize"
|
||||
options[:adapter] = false
|
||||
end
|
||||
options[:original_url] = original_url
|
||||
if options[:pagination]
|
||||
options[:original_url] = original_url
|
||||
options[:query_parameters] = query_parameters
|
||||
end
|
||||
ActiveModel::SerializableResource.serialize(resource, options) do |serializable_resource|
|
||||
if serializable_resource.serializer?
|
||||
serializable_resource.serialization_scope ||= serialization_scope
|
||||
@@ -62,5 +65,9 @@ module ActionController
|
||||
def original_url
|
||||
request.original_url.sub(/\?.*$/, "")
|
||||
end
|
||||
|
||||
def query_parameters
|
||||
request.query_parameters
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user