Articles tagged 'will_paginate'
November 10, 2011
This post was originally published in the Rambling Labs Blog on November 10, 2011.
For a project that I’m currently working on, I have a couple of list views that needed pagination. So I went with the ol’
will_paginategem (which I first saw years ago when I didn’t even consider myself a developer) to take care of this.
It’s as simple as including a line with
gem 'will_paginate'on your
bundle install, and include this in the controller:
class OrdersController < ApplicationController def index @orders = Order.paginate(page: params[:page], per_page: 10) end end
And this in the view
<div id="orders"> <ul> <% @orders.each do |order| %> <li> <!-- Show order stuff --> …