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

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