mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Add pagination links automatically
Pagination links will be included in your response automatically as long as the resource is paginated using Kaminari or WillPaginate and if you are using a JSON-API adapter. The others adapters does not have this feature.
This commit is contained in:
@@ -164,7 +164,7 @@ module ActiveModel
|
||||
def add_links(options)
|
||||
links = @hash.fetch(:links) { {} }
|
||||
resources = serializer.instance_variable_get(:@resource)
|
||||
@hash[:links] = add_pagination_links(links, resources, options) if @options[:pagination]
|
||||
@hash[:links] = add_pagination_links(links, resources, options) if options[:pagination]
|
||||
end
|
||||
|
||||
def add_pagination_links(links, resources, options)
|
||||
|
||||
@@ -14,7 +14,7 @@ module ActiveModel
|
||||
|
||||
def serializable_hash(options = {})
|
||||
pages_from.each_with_object({}) do |(key, value), hash|
|
||||
query_parameters = options.fetch(:query_parameters) { {} }
|
||||
query_parameters = options[:pagination].fetch(:query_parameters) { {} }
|
||||
params = query_parameters.merge(page: { number: value, size: collection.size }).to_query
|
||||
|
||||
hash[key] = "#{url(options)}?#{params}"
|
||||
@@ -51,7 +51,7 @@ module ActiveModel
|
||||
|
||||
def url(options)
|
||||
self_link = options.fetch(:links) {{}}
|
||||
self_link.fetch(:self) {} ? options[:links][:self] : options[:original_url]
|
||||
self_link.fetch(:self) {} ? options[:links][:self] : options[:pagination][:original_url]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user