[Ruby on Rails 4] gems: will_paginate

ページネーション機能をRailsに加えるプラグイン。

gem 'will_paginate'

“`ruby:app/controllers/orders_controller.rb
def index
@orders = Order.paginate page: params[:page],
order: ‘created_at desc’,
per_page: 10
respond_to do |format|
format.html # index.html.erb
format.json { render json: @orders }
end
end

```ruby:app/views/orders/index.html.erb
<p><%= will_paginate @orders %></p>

生成されたページネーション。
http://localhost:3000/orders で確認。

<p><div class="pagination"><span class="previous_page disabled">&#8592; Previous</span> <em class="current">1</em> <a rel="next" href="/orders?page=2">2</a> <a href="/orders?page=3">3</a> <a href="/orders?page=4">4</a> <a href="/orders?page=5">5</a> <a href="/orders?page=6">6</a> <a href="/orders?page=7">7</a> <a href="/orders?page=8">8</a> <a href="/orders?page=9">9</a> <a href="/orders?page=10">10</a> <a class="next_page" rel="next" href="/orders?page=2">Next &#8594;</a></div></p>