Created
January 12, 2012 18:23
-
-
Save citrus/1602209 to your computer and use it in GitHub Desktop.
Sequel pagination with Kaminari
This file contains hidden or 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
# config/initializers/sequel.rb | |
module Kaminari | |
module Sequel | |
def self.included(base) | |
base.class_eval do | |
alias :num_pages :page_count | |
alias :limit_value :page_size | |
end | |
::Sequel::Dataset.class_eval do | |
def paginate_with_safe_page(page_no, page_size, record_count=nil) | |
page_no = page_no.to_i | |
page_no = page_no == 0 ? 1 : page_no | |
paginate_without_safe_page(page_no, page_size, record_count) | |
end | |
alias_method_chain :paginate, :safe_page | |
end | |
end | |
end | |
end | |
Sequel.extension :pagination | |
Sequel::Dataset::Pagination.send(:include, Kaminari::Sequel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code does not work on Rails 5.1 anymore.
I have created a gem for that: https://github.com/sekrett/kaminari-sequel