[Ruby on Rails 3, Ruby on Rails 4] gems: will_paginate
ページネーション機能をRailsに加えるプラグイン。
[markdown]
“`ruby
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
<%= will_paginate @orders %>
“`
生成されたページネーション。
http://localhost:3000/orders で確認。
“`html
“`
[/markdown]