Skip to content

Commit 0cfadb5

Browse files
authored
Add hook for automatic pagination links. (#35)
1 parent 1b3af0a commit 0cfadb5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/jsonapi/rails/action_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def deserializable_resource(key, options = {}, &block)
4242
end
4343
end
4444

45+
def jsonapi_pagination(_collection)
46+
nil
47+
end
48+
4549
def jsonapi_pointers
4650
request.env[JSONAPI_POINTERS_KEY]
4751
end

lib/jsonapi/rails/railtie.rb

Lines changed: 6 additions & 0 deletions
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)