Skip to content

Instantly share code, notes, and snippets.

@kirqe
Created April 19, 2018 23:36
Show Gist options
  • Save kirqe/c62c846397a99bafeebb077aab2a725f to your computer and use it in GitHub Desktop.
Save kirqe/c62c846397a99bafeebb077aab2a725f to your computer and use it in GitHub Desktop.
simple api pagination
gem 'jbuilder', '~> 2.5'
gem 'kaminari'
json.topics @topics do |topic|
json.id topic.id
json.body topic.body
end
if @topics.next_page
json.next_href api_board_topics_url(page: @topics.next_page)
end
{
"topics": [
],
"next_href": "http://localhost:3000/api/boards/renner/topics?page=2"
}
}
def index
@topics = @board.topics.latest.page(params[:page]).per(20)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment