Skip to content

Instantly share code, notes, and snippets.

@firedev
Created February 7, 2014 11:14
Show Gist options
  • Save firedev/8860905 to your computer and use it in GitHub Desktop.
Save firedev/8860905 to your computer and use it in GitHub Desktop.
Kaminari pager fix – keeps consistent number of pages on the screen
# config/initializers/kaminari.rb
module Kaminari
module Helpers
class Paginator < Tag
def relevant_pages(options)
1..options[:total_pages]
end
class PageProxy
def inside_window?
if @options[:current_page] <= @options[:window]
@page <= (@options[:window] * 2) + 1
elsif (@options[:total_pages] - @options[:current_page].number) < @options[:window]
@page >= (@options[:total_pages] - (@options[:window] * 2))
else
(@options[:current_page] - @page).abs <= @options[:window]
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment