will_paginate

最近、ruby-rails環境を使ってちょっとしたアプリを作っています。
そこでちょっとはまったのでまとめ

will_paginateというページ送り機能のプラグインをインストールする。

まずはgemでwill_paginateをインストール。

> gem install will_paginate enter
Successfully installed will_paginate-2.3.15
1 gem installed
Installing ri documentation for will_paginate-2.3.15...
Installing RDoc documentation for will_paginate-2.3.15...

次に、will_paginateを使うアプリのconfig/environment.rb内に以下を記述

require 'will_paginate'


ここでさっそくエラーが

rails server
=> Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/config/environment.rb:4:in `require': no such file to load -- will_paginate (LoadError)
	from /config/environment.rb:4
	from /config.ru:3:in `require'
	from /config.ru:3
	from /vendor/bundle/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
	from /vendor/bundle/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
	from /config.ru:1:in `new'
	from /config.ru:1

config/environment.rbからwill_paginateが呼び出せていないよう。

調べてみるとどうやらGemfileに記述しなければいけないらしいので
さっそく下の行をGemfileに書き加える

gem 'will_paginate'

Gemfileに書き加えた後はbundleで更新しなければならないらしい。

>bundle check
Your Gemfile's dependencies could not be satisfied
Install missing gems with `bundle install`
>sudo bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Using abstract (1.0.0) 
…
Using twitter (0.9.8) 
Installing will_paginate (2.3.15) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Your bundle was installed to `vendor/bundle`

これでインストールと設定は完了。

参考URL
『will_paginateをインストール、設定しよう Ruby on Rails Pro』
http://maskana.homedns.org/rails/pro/body/103
『第11回: Bundler - Ruby on Rails 3.0 日記 - Ruby on Rails with OIAX』
http://www.oiax.jp/rails/rails3/bundler.html