# How to paginate an model array object

**URL:** <https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616>\
**Category:** Rails\
**Created:** [December 19, 2007, 8:07am UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616 "2007-12-19T08:07:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 19, 2007, 8:07am UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616/1 "2007-12-19T08:07:27Z")

</div>

@models=Model.find\_all  
@model\_pages,@models=paginate @models,:per\_page=\>10

ofcourse above is wrong

is there any way to do like that in rails ?

actually i have created my own Class method in Model.rb .  
From that i can get array of model object.

i want to paginate that

any idea …

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 19, 2007, 8:33am UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616/2 "2007-12-19T08:33:25Z")

</div>

[http://wiki.rubyonrails.org/rails/pages/PaginationHelper](http://wiki.rubyonrails.org/rails/pages/PaginationHelper)  
[http://wiki.rubyonrails.org/rails/pages/HowtoPagination](http://wiki.rubyonrails.org/rails/pages/HowtoPagination)  
Also check out for will\_paginate plugin

Pokkai D. wrote:

> @models=Model.find\_all  
> @model\_pages,@models=paginate @models,:per\_page=\>10
> 
> ofcourse above is wrong
> 
> is there any way to do like that in rails ?
> 
> actually i have created my own Class method in Model.rb .  
> From that i can get array of model object.
> 
> i want to paginate that
> 
> any idea …

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 19, 2007, 10:23am UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616/3 "2007-12-19T10:23:25Z")

</div>

In controller:

@models = Model.paginate :page =\> params[:page], :per\_page =\> PAGE\_SIZE,  
:conditions =\> yr\_condition

In View:

\<%= will\_paginate @models %\>

Before this as a first step install will\_paginate plugin since  
pagination concept is removed from core rails 2.0 and released as a  
plugin

U can install the plugin by typing this navigating to the project folder

(example:  
E:\My Rails Application\>ruby script/plugin install  
svn://errtheblog.com/svn/plugins/will\_paginate)

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 19, 2007, 3:23pm UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616/4 "2007-12-19T15:23:45Z")

</div>

Ratnavel S. wrote:

> In controller:
> 
> @models = Model.paginate :page =\> params[:page], :per\_page =\> PAGE\_SIZE,  
> :conditions =\> yr\_condition
> 
> In View:
> 
> \<%= will\_paginate @models %\>
> 
> Before this as a first step install will\_paginate plugin since  
> pagination concept is removed from core rails 2.0 and released as a  
> plugin
> 
> U can install the plugin by typing this navigating to the project folder
> 
> (example:  
> E:\My Rails Application\>ruby script/plugin install  
> svn://errtheblog.com/svn/plugins/will\_paginate)

what about if i using params[:variable] in the case of getting my  
collection  
like that

@users=User.find(:all,:conditions=\>[“sex=?”,params[:sex]])

---

<div class="post-metadata">

**Author:** ![mokkai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c2a13f/32.png) [@mokkai](https://www.ruby-forum.com/u/mokkai)\
**Post date:** [December 20, 2007, 12:09am UTC](https://www.ruby-forum.com/t/how-to-paginate-an-model-array-object/123616/5 "2007-12-20T00:09:42Z")

</div>

What version of Rails are you using? Pagination has been taken out of  
the  
core and put into a plugin as of Rails 2.0. It’s now recommended to use  
will\_paginate as a replacement.

On Dec 20, 2007 12:53 AM, Pokkai D.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > 
> 
> what about if i using params[:variable] in the case of getting my  
> collection  
> like that
> 
> @users=User.find(:all,:conditions=\>[“sex=?”,params[:sex]])
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.  
[http://www.frozenplague.net](http://www.frozenplague.net)
