0
+Quick quiz: Where does pagination logic belong?
0
+We think you know the answer (if you think hard enough).
0
+This plugin makes magic happen. You *will* paginate!
0
+Use a paginate finder in the controller:
0
+ @posts = Post.paginate_by_board_id @board.id, :page => params[:page]
0
+Yeah, `paginate` works just like `find` -- it just doesn't fetch all the records.
0
+Just don't forget to tell it which page you want!
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.)
0
+How does it know how much items to fetch per page? It asks your model by calling
0
+`Post.per_page`. 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 30 if missing.)
0
+You can also specify the count explicitly when calling `paginate`:
0
+ @posts = Post.paginate :page => params[:page], :per_page => 50
0
+Find more options in sections below.
0
+The `paginate` finder wraps the original finder and returns a PaginatedCollection
0
+instance that's in fact a proxy to the original collection. You can use the collection
0
+as you would any ActiveRecord resultset, but WillPaginate view helpers also need the
0
+object to know how to make 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
+In model finders, "all" is implicit. No sense in paginating a single record, right?
0
+ * Post.paginate => Post.find :all
0
+ * Post.paginate_all_by_something => Post.find_all_by_something
0
+ * Post.paginate_by_something => Post.find_all_by_something
0
+Options for `paginate` finders are:
0
+ * per_page (default is read from the model, which is 30 if not overriden)
0
+ * total entries: ActiveRecord knows how to count, but you can still override it
0
+ * count: takes place of "select" for count() statement
0
+ * distinct: also just for count() statement
0
+Options for `will_paginate` view helper:
0
+ * class: CSS class name for the generated DIV (default "pagination")
0
+ * prev_label: default '« Previous',
0
+ * next_label: default 'Next »',
0
+ * inner_window: how many links are shown around the current page, defaults to 4
0
+ * outer_window: how many links are around the first and the last page, defaults to 1
0
+Ruby port by: PJ Hyett, Mislav Marohnić (Sulien)
0
+Contributors: K. Adam Christensen, Chris Wanstrath, Dr. Nic Williams
0
+Original announcement: http://errtheblog.com/post/929
0
+Original PHP source: http://www.strangerstudios.com/sandbox/pagination/diggstyle.php
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;