Skip to content

Instantly share code, notes, and snippets.

@jocap
Created December 5, 2010 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jocap/729108 to your computer and use it in GitHub Desktop.
Save jocap/729108 to your computer and use it in GitHub Desktop.
Ruby Pagination Logic with DataMapper and Sinatra: http://jocap.github.com/Ruby-Pagination-Logic/
# @app.rb
[...]
require "ruby_pagination_logic"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment