ruby_pagination_logic

Installation

$ sudo gem install ruby_pagination_logic

Example use

# With DataMapper and Sinatra
# @app.rb
[...]
require "pagination.rb"
get '/page/:page' do |page|
  @page = page.to_i
  limit = 5
  offset = RPL::paginate @page, limit

  @post = Post.all :limit => limit, :offset => offset, :order => 'date'

  haml :posts
end

# @views/posts.haml
%section{:class => "articles"}
  - @post.reverse.each do |post|
    %article
      %h2
        =post.title
      = post.date
      %div
        = post.text
%a{:href => "/page/#{RPL::next @page}"}
  Next

Author: John Ankarström. Source.

Contributing to ruby_pagination_logic

License

Based on CC-BY-SA 3.0.

You must give attribution in source code, although not on website (if you’re using it for your website). If you make any modifications, please publish it under the this license, CC-BY-SA 3.0, and give attribution.