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

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