# Pagination

**URL:** <https://www.ruby-forum.com/t/pagination/144502>\
**Category:** Rails\
**Created:** [July 30, 2008, 12:34pm UTC](https://www.ruby-forum.com/t/pagination/144502 "2008-07-30T12:34:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jokrish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8edcca/32.png) [@jokrish](https://www.ruby-forum.com/u/jokrish)\
**Post date:** [July 30, 2008, 12:34pm UTC](https://www.ruby-forum.com/t/pagination/144502/1 "2008-07-30T12:34:43Z")

</div>

I want to do pagination in my project.For that i installed  
gem install mislav-will\_paginate --source [http://gems.github.com/](http://gems.github.com/) .  
then i wrote require ‘will\_paginate’ in my enviornment.rb file.  
anything else required?  
Then am i able to use it for my application?  
how can i call it from my controller.I tried to call paginate…but  
error is showing that undefined method paginate…  
can anybody help me?

---

<div class="post-metadata">

**Author:** ![jokrish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8edcca/32.png) [@jokrish](https://www.ruby-forum.com/u/jokrish)\
**Post date:** [July 30, 2008, 1:11pm UTC](https://www.ruby-forum.com/t/pagination/144502/2 "2008-07-30T13:11:03Z")

</div>

> then i wrote require ‘will\_paginate’ in my enviornment.rb file.  
> anything else required?

that’s all to it. if you can start script/server and get no errors for  
it, it should be ok so far.

to actually paginate something do this (example for model named  
Product):

@products = Product.paginate(:all, :order =\> “products.created\_at  
DESC”,  
:page =\>  
params[:page].to\_i, :per\_page =\> params[:per\_page].to\_i)

mind, that params[:page] & params[:per\_page] should be initialized  
properly  
per\_page should be 1 for first call and set to other pages for further  
calls. but will\_paginate will  
handle most of it.

in the view you get the pagination links like that:  
\<% unless @products.nil? or @products.empty?%\>  
\<%= will\_paginate @products, :inner\_window =\> 2 %\>  
\<% else %\>  
found nothing  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![jokrish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8edcca/32.png) [@jokrish](https://www.ruby-forum.com/u/jokrish)\
**Post date:** [August 6, 2008, 11:50am UTC](https://www.ruby-forum.com/t/pagination/144502/3 "2008-08-06T11:50:47Z")

</div>

I got error like this…  
undefined method `paginate’ for #Class:0x466c408

RAILS\_ROOT: C:/InstantRails-2.0-win(3)/rails\_apps/invictold  
Application Trace | Framework Trace | Full Trace

vendor/rails/activerecord/lib/active\_record/base.rb:1667:in  
`method_missing' app/models/customer.rb:8:in`search’  
app/controllers/customers\_controller.rb:6:in `index’

can anybody help me…

---

<div class="post-metadata">

**Author:** ![jokrish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8edcca/32.png) [@jokrish](https://www.ruby-forum.com/u/jokrish)\
**Post date:** [August 7, 2008, 3:19am UTC](https://www.ruby-forum.com/t/pagination/144502/4 "2008-08-07T03:19:07Z")

</div>

Classic pagination has been moved into a plugin since 2.0.
