mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
return complete URIs on pagination links
This commit is contained in:
@@ -29,7 +29,7 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
include_pagination_links if serializer.pagination
|
||||
include_pagination_links if serializer.options[:pagination]
|
||||
else
|
||||
@hash[:data] = attributes_for_serializer(serializer, options)
|
||||
add_resource_relationships(@hash[:data], serializer)
|
||||
@@ -168,7 +168,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def page_links
|
||||
@links ||= JsonApi::PaginationLinks.new(serializer.resource).page_links
|
||||
@links ||= JsonApi::PaginationLinks.new(serializer.resource, serializer.options).page_links
|
||||
end
|
||||
|
||||
def links?
|
||||
|
||||
@@ -5,11 +5,12 @@ module ActiveModel
|
||||
class PaginationLinks
|
||||
FIRST_PAGE = 1
|
||||
|
||||
attr_reader :collection
|
||||
attr_reader :collection, :options
|
||||
|
||||
def initialize(collection)
|
||||
def initialize(collection, options={})
|
||||
raise_unless_any_gem_installed
|
||||
@collection = collection
|
||||
@options = options
|
||||
end
|
||||
|
||||
def page_links
|
||||
@@ -20,7 +21,7 @@ module ActiveModel
|
||||
|
||||
def build_links
|
||||
pages_from.each_with_object({}) do |(key, value), hash|
|
||||
hash[key] = "?page=#{value}&per_page=#{collection.size}"
|
||||
hash[key] = "#{url}?page=#{value}&per_page=#{collection.size}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,6 +46,15 @@ module ActiveModel
|
||||
raise "AMS relies on either Kaminari or WillPaginate." +
|
||||
"Please install either dependency by adding one of those to your Gemfile"
|
||||
end
|
||||
|
||||
def url
|
||||
return default_url unless options && options[:links] && options[:links][:self]
|
||||
options[:links][:self]
|
||||
end
|
||||
|
||||
def default_url
|
||||
options[:original_url]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user