Forward-only filtered pager
Add this line to your application's Gemfile:
gem 'pager'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pager
class Array
include Pager
end
To start filtering and returns first 25 filtered posts:
posts = Post.all.to_a
@posts = posts.filtered_page(25) do |post|
post.published?
end # => get the first 25 filtered posts
@posts2 = posts.filtered_page(25) do |post|
post.published?
end # => get the next 25 filtered posts
To start filtering starts from explicit element:
@posts = posts.filtered_page(25, offset: Post.all[2]) do |post|
post.published?
end
To get current offset
@posts = posts.filtered_page(25, offset: Post.all[2]) do |post|
post.published?
end
next_offset = posts.current_offset
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request