# Paginate [![Build Status](https://travis-ci.org/fnando/paginate.png)](https://travis-ci.org/fnando/paginate) [![CodeClimate](https://codeclimate.com/github/fnando/paginate.png)](https://codeclimate.com/github/fnando/paginate/) Paginate collections using SIZE+1 to determine if there is a next page. Includes ActiveRecord and ActionView support. Works only with **Rails 3+**. ## Install ```bash gem install paginate ``` ## Usage You can use Paginate with or without ActiveRecord. Let's try a simple array pagination. Imagine that you have something like this in your controller. ```ruby @things = Array.new(11) {|i| "Item #{i}"} ``` Then on your view: ```erb <%= paginate @things %> ``` That's it! This is all you have to do! In this case we're using the default page size (which is 10). The url used on page links is taken from the current requested uri. You can set default values globally: ```ruby Paginate.configure do |config| config.size = 20 config.param_name = :p end ``` More examples: ```ruby Post.paginate(1) # page 1 from Post model Post.paginate(page: 1) # page 1 from Post model Post.paginate(page: 1, size: 5) # page 1 from Post model with custom size @user.things.paginate(:page => params[:page]) # paginate association ``` ```erb <%= paginate @things, size: 5 %> <%= paginate @things, url: -> page { things_path(:page => page) } %> <%= paginate @things, "/some/path" %> <%= paginate @things, param_name: :p %> ``` To render the collection, you must use the render helper, providing the :paginate => true option. This is required cause we're always considering SIZE + 1, so if you use the regular +each+ or don't pass this option, you end up rendering one additional item. ```erb <%= render @things, paginate: true %> <%= render @things, paginate: true, size: 5 %> <%= render "thing", collection: @things, paginate: true, size: 5 %> ``` ## I18n support If you want to translate links, you have implement the following scopes: ```yaml en: paginate: next: "Older" previous: "Newer" page: "Page {{page}}" more: "Load more" ``` ## Styling If you want something like Twitter Search use this CSS: ```css .paginate { overflow: hidden; } .paginate li { float: left; } .paginate li.previous-page:after { content: "«"; padding: 0 5px; } .paginate li.next-page:before { content: "»"; padding: 0 5px; } .paginate .disabled { display: none; } ``` You can create new renderers. Paginate comes with two renderers. * `Paginate::Renderer::List`: is the default renderer. Uses a `