Skip to content

Commit c763af2

Browse files
committed
Add hook for automatic pagination links.
1 parent aac9514 commit c763af2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/jsonapi/rails/action_controller.rb

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def deserializable_resource(key, options = {}, &block)
4040
end
4141
end
4242

43+
def jsonapi_pagination(_collection)
44+
nil
45+
end
46+
4347
def jsonapi_pointers
4448
request.env[JSONAPI_POINTERS_KEY]
4549
end

lib/jsonapi/rails/railtie.rb

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ class Railtie < ::Rails::Railtie
3030
::ActionController::Renderers.add(:jsonapi) do |resources, options|
3131
self.content_type ||= Mime[:jsonapi]
3232

33+
# Renderer proc is evaluated in the controller context, so it
34+
# has access to the jsonapi_pagination method.
35+
if (pagination_links = jsonapi_pagination(resources))
36+
(options[:links] ||= {}).merge!(pagination_links)
37+
end
38+
3339
RENDERERS[:jsonapi].render(resources, options).to_json
3440
end
3541

0 commit comments

Comments
 (0)