Created
April 19, 2018 23:36
-
-
Save kirqe/c62c846397a99bafeebb077aab2a725f to your computer and use it in GitHub Desktop.
simple api pagination
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'jbuilder', '~> 2.5' | |
gem 'kaminari' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"topics": [ | |
], | |
"next_href": "http://localhost:3000/api/boards/renner/topics?page=2" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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