Created
December 5, 2010 14:07
-
-
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/
This file contains 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
# @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 |
This file contains 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
-# @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