Skip to content

Instantly share code, notes, and snippets.

@dwhenry
dwhenry / controller_example.rb
Last active August 29, 2015 14:26 — forked from plcstevens/controller_example.rb
Include this in controllers and render with your JSON to get pagination URLs matching http://jsonapi.org/format/#fetching-pagination specification. Requires that you use https://github.com/amatsuda/kaminari
class ExamplesController < ApplicationController
include Pagination
def index
@examples = Example.order(id: :desc)
render json: { pagination: paginate(@examples), examples: @examples }
end
end