return complete URIs on pagination links

This commit is contained in:
Bruno Bacarini
2015-08-10 11:04:48 -03:00
parent 36c452e60b
commit e62a7d6f34
9 changed files with 51 additions and 22 deletions

View File

@@ -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?

View File

@@ -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

View File

@@ -5,7 +5,7 @@ module ActiveModel
include Enumerable
delegate :each, to: :@objects
attr_reader :root, :meta, :meta_key, :pagination, :resource
attr_reader :root, :meta, :meta_key, :options, :resource
def initialize(objects, options = {})
@root = options[:root]
@@ -24,7 +24,7 @@ module ActiveModel
end
@meta = options[:meta]
@meta_key = options[:meta_key]
@pagination = options[:pagination]
@options = options
end
def json_key