Skip to content

Instantly share code, notes, and snippets.

@ghiden
Created June 23, 2010 02:47
Show Gist options
  • Save ghiden/449422 to your computer and use it in GitHub Desktop.
Save ghiden/449422 to your computer and use it in GitHub Desktop.
# using Paginator with MongoMapper
# index action in a controller
def index
@pager = Paginator.new(User.count, 20) do |offset, per_page|
User.all(:offset => offset, :limit => per_page, :order => "created_at DESC")
end
@users = @pager.page(params[:page])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
end
end
<!-- This should show page numbers, 1 2 3 ... with hyperlinks -->
<% ([email protected]_of_pages).to_a.each do |p| %>
<%= p == @users.number ? p : link_to(p, users_path(:page => p)) %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment