def respond_with_paginated(collection)
%w( current_page
total_pages
total_count
prev_page
next_page
first_page?
last_page?
).each do |method_name|
field_name = "X-Kaminari-#{method_name.titleize.gsub(/\s/, '-')}"
field_value = collection.send(:"#{method_name}").to_s
response.headers[field_name] = field_value
end
response.headers['X-Kaminari'] = "true"
respond_with(collection)
end
Last active
August 29, 2015 14:13
-
-
Save drfeelngood/91195aad5b39b49c76a2 to your computer and use it in GitHub Desktop.
Rails API pagination with kaminari using http headers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Herm, I just learned about the Link HTTP header. RFC-5988 is probably a better solution.