Skip to content

Instantly share code, notes, and snippets.

@shqear93
Created August 19, 2021 19:34
Show Gist options
  • Save shqear93/17957824532f057388aa3ce05bab2f58 to your computer and use it in GitHub Desktop.
Save shqear93/17957824532f057388aa3ce05bab2f58 to your computer and use it in GitHub Desktop.
Pagination list algorithm for ruby
def pagination_list
range = (0..maximum_pages_number).to_a
adjacent = (@pages_in_bar / 2).floor * 2 + 1
range[[0, [range.size - 1 - adjacent, page_number.to_i - (adjacent / 2).ceil].min].max, adjacent] if adjacent >= 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment