0
Some resources to get you started:
0
-* Your mind reels with questions? Join our Google
0
- group[http://groups.google.com/group/will_paginate].
0
+* Your mind reels with questions? Join our
0
+ {Google group}[http://groups.google.com/group/will_paginate].
0
* The will_paginate project page: http://github.com/mislav/will_paginate
0
* How to report bugs: http://github.com/mislav/will_paginate/wikis/report-bugs
0
* Ryan Bates made an awesome screencast[http://railscasts.com/episodes/51],
0
-
Previously, the plugin was available on the following SVN location:
0
+
The recommended way is that you get the gem:
0
- svn://errtheblog.com/svn/plugins/will_paginate
0
+ # add GitHub to your local list of gem sources:
0
+ gem sources -a http://gems.github.com/
0
+ gem install mislav-will_paginate
0
-In February 2008, it moved to GitHub to be tracked with git version control.
0
-The SVN repo continued to have updates for some time, but now it doesn't.
0
+After that you don't need the will_paginate <i>plugin</i> in your Rails
0
+application anymore. Just add a simple require to the end of
0
+"config/environment.rb":
0
-You should switch to using the gem:
0
- gem install will_paginate
0
-After that, you can remove the plugin from your application and add
0
-a simple require to the end of config/environment.rb:
0
+ gem 'mislav-will_paginate', '~> 2.2'
0
require 'will_paginate'
0
-That's it, just remember to install the gem on all machines that
0
+That's it. Remember to install the gem on <b>all</b> machines that you are
0
-installation[http://github.com/mislav/will_paginate/wikis/installation]
0
-instructions on the wiki[http://github.com/mislav/will_paginate/wikis].</i>
0
+{installation instructions}[http://github.com/mislav/will_paginate/wikis/installation]
0
+on {the wiki}[http://github.com/mislav/will_paginate/wikis].</i>
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
+
@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
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
+
<%= 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
+ cattr_reader :per_page
0
- class Post < ActiveRecord::Base
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
+
@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
+ <% 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
+ <p>Now let's render us some pagination!</p>
0
+ <%= will_paginate @posts %>
0
More detailed documentation:
0
* Pagination on Yahoo Design Pattern Library:
0
http://developer.yahoo.com/ypatterns/parent.php?pattern=pagination
0
-Want to discuss, request features, ask questions? Join the Google group:
0
-http://groups.google.com/group/will_paginate
0
+Want to discuss, request features, ask questions? Join the
0
+{Google group}[http://groups.google.com/group/will_paginate].
Comments
No one has commented yet.