Created
August 27, 2010 14:38
-
-
Save ryana/553473 to your computer and use it in GitHub Desktop.
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
class RawRenderer < WillPaginate::LinkRenderer | |
def prepare col, opt, template | |
@collection = col | |
@options = opt | |
@options[:container] = nil | |
@template = template | |
@total_pages = @collection.total_pages | |
end | |
def page_link(page, text, attr = {}) | |
"<a href='/#{root_page}?page=#{page}'>#{text}</a>" | |
end | |
def root_page | |
"items" | |
end | |
def page_span(page, text, attr = {}) | |
"<span>#{text}</span>" | |
end | |
end | |
WillPaginate::ViewHelpers.pagination_options[:renderer] = RawRenderer |
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
# Use will_paginate, Record is a MongoMapper document class. This is in your sinatra app: | |
require 'will_paginate' | |
require 'will_paginate/collection' | |
require 'will_paginate/view_helpers' | |
helpers do | |
include WillPaginate::ViewHelpers | |
end | |
# note /items is same as #root_page in the renderer | |
get '/items' do | |
limit = 20 | |
page = params[:page] || 1 | |
page = page.to_i | |
page -= 1 | |
offset = limit * page | |
records = Records.all :limit => limit, :offset => offset | |
@records = WillPaginate::Collection.create(page + 1, limit, Record.count) {|p| p.replace records } | |
erb :your_view | |
end |
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
# just use will_paginate | |
<%= will_paginate @items %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment