0
-Pagination is just limiting the number of records displayed. Why should you let
0
-it get in your way while developing, then? This plugin makes magic happen. Did
0
-you ever want to be able to do just this on a model:
0
- Post.paginate :page => 1, :order => 'created_at DESC'
0
-... and then render the page links with a single view helper? Well, now you
0
-Ryan Bates made an awesome screencast[http://railscasts.com/episodes/51],
0
-Your mind reels with questions? Join our Google
0
-group[http://groups.google.com/group/will_paginate].
0
-Will Paginate officially supports Rails versions 1.2.6 and 2.0.x.
0
-Previously, the plugin was available on the following SVN location:
0
- svn://errtheblog.com/svn/plugins/will_paginate
0
-In February 2008, it moved to GitHub[http://github.com/mislav/will_paginate/tree]
0
-to be tracked with git. The SVN repo continued to have updates, but not
0
-forever. Therefore you should switch to using the gem:
0
- gem install will_paginate
0
-After that, you can remove the plugin from your applications and add
0
-a simple require to the end of config/environment.rb:
0
- require 'will_paginate'
0
-That's it, just remember to install the gem on all machines that
0
-The second option is to download and extract the tarball from GitHub. Here is the
0
-link for downloading the current state of the master branch:
0
-http://github.com/mislav/will_paginate/tarball/master
0
-Extract it to <tt>vendor/plugins</tt>. The directory will have a default name
0
-like "mislav-will_paginate-master"; you can rename it to "will_paginate" for
0
-Use a paginate finder in the controller:
0
- @posts = Post.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'
0
-Yeah, +paginate+ works just like +find+ -- it just doesn't fetch all the
0
-records. Don't forget to tell it which page you want, or it will complain!
0
-Read more on WillPaginate::Finder::ClassMethods.
0
-Render the posts in your view like you would normally do. When you need to render
0
-pagination, just stick this in:
0
- <%= will_paginate @posts %>
0
-You're done. (Copy and paste the example fancy CSS styles from the bottom.) You
0
-can find the option list at WillPaginate::ViewHelpers.
0
-How does it know how much items to fetch per page? It asks your model by calling
0
-its <tt>per_page</tt> class method. You can define it like this:
0
- class Post < ActiveRecord::Base
0
- cattr_reader :per_page
0
- class Post < ActiveRecord::Base
0
-... or don't worry about it at all. WillPaginate defines it to be <b>30</b> by default.
0
-But you can always specify the count explicitly when calling +paginate+:
0
- @posts = Post.paginate :page => params[:page], :per_page => 50
0
-The +paginate+ finder wraps the original finder and returns your resultset that now has
0
-some new properties. You can use the collection as you would with any ActiveRecord
0
-resultset. WillPaginate view helpers also need that object to be able to render pagination:
0
- <% for post in @posts -%>
0
- <li>Render `post` in some nice way.</li>
0
- <p>Now let's render us some pagination!</p>
0
- <%= will_paginate @posts %>
0
-More detailed documentation:
0
-* WillPaginate::Finder::ClassMethods for pagination on your models;
0
-* WillPaginate::ViewHelpers for your views.
0
-Tell us what happened so we can fix it, quick! Issues are filed on the Lighthouse project:
0
-http://err.lighthouseapp.com/projects/466-plugins/tickets?q=tagged:will_paginate
0
-Steps to make an awesome bug report:
0
-1. Run <tt>rake test</tt> in the <i>will_paginate</i> directory. (You will need SQLite3.)
0
- Copy the output if there are failing tests.
0
-2. Register on Lighthouse to create a new ticket.
0
-3. Write a descriptive, short title. Provide as much info as you can in the body.
0
- Assign the ticket to Mislav and tag it with meaningful tags, <tt>"will_paginate"</tt>
0
-4. Yay! You will be notified on updates automatically.
0
-Here is an example of a great bug report and patch:
0
-http://err.lighthouseapp.com/projects/466/tickets/172-total_entries-ignored-in-paginate_by_sql
0
-== Authors, credits, contact
0
-Want to discuss, request features, ask questions? Join the Google group:
0
-http://groups.google.com/group/will_paginate
0
-Authors:: Mislav Marohnić, PJ Hyett
0
-Original announcement:: http://errtheblog.com/post/929
0
-Original PHP source:: http://www.strangerstudios.com/sandbox/pagination/diggstyle.php
0
-All these people helped making will_paginate what it is now with their code
0
-contributions or just simply awesome ideas:
0
-Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
0
-Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
0
-van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
0
-== Usable pagination in the UI
0
-Copy the following CSS into your stylesheet for a good start:
0
- padding: 2px 5px 2px 5px;
0
- border: 1px solid #aaaadd;
0
- text-decoration: none;
0
- .pagination a:hover, .pagination a:active {
0
- border: 1px solid #000099;
0
- .pagination span.current {
0
- padding: 2px 5px 2px 5px;
0
- border: 1px solid #000099;
0
- background-color: #000099;
0
- .pagination span.disabled {
0
- padding: 2px 5px 2px 5px;
0
- border: 1px solid #eee;
0
-More reading about pagination as design pattern:
0
- http://kurafire.net/log/archive/2007/06/22/pagination-101
0
- http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/
0
-* Pagination on Yahoo Design Pattern Library:
0
- http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination