1.controller
定义action,指定需要翻页,示例代码:
def list
@product_pages, @products = paginate :products, :per_page => 10
end
@product_pages记录页数信息,@products每页的集合,每页10条记录
2.view
<table>
<tr>
<% for column in Product.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<% for product in @products %>
<tr>
<% for column in Product.content_columns %>
<td><%=h product.send(column.name) %></td>
<% end %>
</tr>
<% end %>
</table>
<%= link_to 'Previous page',
{ :page => @product_pages.current.previous } if @product_pages.current.previous %>
<%= link_to 'Next page',
{ :page => @product_pages.current.next } if @product_pages.current.next %>