[Ruby] ページング機能を追加する「will_paginate」

Tue, December 4, 2012 - 3 min read

Rubyでページング機能を追加するGem「will_paginate」の使い方をメモ。

mislav/will_paginate はてなブックマーク - mislav/will_paginate

Home · mislav/will_paginate Wiki はてなブックマーク - Home · mislav/will_paginate Wiki

Translating will_paginate output (i18n) · mislav/will_paginate Wiki はてなブックマーク - Translating will_paginate output (i18n) · mislav/will_paginate Wiki

will_paginate | RubyGems.org | your community gem host はてなブックマーク - will_paginate | RubyGems.org | your community gem host

Rails 3 + will_paginate 3.0.pre2でAjax対応なリンクを生成する | TechRacho はてなブックマーク - Rails 3 + will_paginate 3.0.pre2でAjax対応なリンクを生成する | TechRacho

Ruby on Rails 3でwill_paginateを使ってみた。 - cys b はてなブックマーク - Ruby on Rails 3でwill_paginateを使ってみた。 - cys b

■ オプション一覧

# ==== Options
# * :class -- CSS class name for the generated DIV (default: "pagination")
# * :previous_label -- default: "« Previous"
# * :next_label -- default: "Next »"
# * :page_links -- when false, only previous/next links are rendered (default: true)
# * :inner_window -- how many links are shown around the current page (default: 4)
# * :outer_window -- how many links are around the first and the last page (default: 1)
# * :link_separator -- string separator for page HTML elements (default: single space)
# * :param_name -- parameter name for page number in URLs (default: :page)
# * :params -- additional parameters when generating pagination links
#   (eg. :controller => "foo", :action => nil)
# * :renderer -- class name, class or instance of a link renderer (default in Rails:
#   WillPaginate::ActionView::LinkRenderer)
# * :page_links -- when false, only previous/next links are rendered (default: true)
# * :container -- toggles rendering of the DIV container for pagination links, set to
#   false only when you are rendering your own pagination markup (default: true)

will_paginate/lib/will_paginate/view_helpers.rb at master · mislav/will_paginate はてなブックマーク - will_paginate/lib/will_paginate/view_helpers.rb at master · mislav/will_paginate

will_paginateのオプション設定でpaginationの外観を変更する方法 - memo.yomukaku.net はてなブックマーク - will_paginateのオプション設定でpaginationの外観を変更する方法 - memo.yomukaku.net

will_paginateヘルパーのオプション覚書 - screw it! はてなブックマーク - will_paginateヘルパーのオプション覚書 - screw it!

国際化対応(i18n対応)

i18n対応だけど、ここで初期値をセットしておくと楽。

■ config/locales/will_paginate.ja.yml

ja:
  will_paginate:
    previous_label: "<"
    next_label: ">"
    page_gap: "..."

ページング出力のHTMLタグカスタマイズ

Roll your own pagination links with will_paginate – UK Specialists in Ruby on Rails, Exalead, AWS, Consultancy はてなブックマーク - Roll your own pagination links with will_paginate – UK Specialists in Ruby on Rails, Exalead, AWS, Consultancy