# Paginating 3 arrays of 3 differnet model

**URL:** <https://www.ruby-forum.com/t/paginating-3-arrays-of-3-differnet-model/138455>\
**Category:** Rails\
**Created:** [May 23, 2008, 7:52am UTC](https://www.ruby-forum.com/t/paginating-3-arrays-of-3-differnet-model/138455 "2008-05-23T07:52:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 23, 2008, 7:52am UTC](https://www.ruby-forum.com/t/paginating-3-arrays-of-3-differnet-model/138455/1 "2008-05-23T07:52:56Z")

</div>

Hi  
I have there arrays i get like below in controller  
@hardware\_cis=HardwareCi.find\_where(:all)  
@software\_cis=SoftwareCi.find\_where(:all)  
@document\_cis= documentCi.find\_where(:all)  
The above I have to rearrange to get the pagination  
The above as a whole i have to paginate .For example @hardware\_cis  
may contain some 10 items @software\_cis may contain 6 items and the  
other some 12 items…And i have to paginate total 15 items per page like  
5 from each…And in the view I am iterating through each three like

## \<% for document\_ci in @document\_cis %\> code—

## \<% for software\_ci in @software\_cis %\> code–

## \<% for hardware\_ci in @hardware\_cis %\>

I treid like  
@hardware\_cis=HardwareCi.paginate  
per\_page=\>5,:page=\>params[:hardware\_page]  
@software\_cis=SoftwareCi.paginate  
per\_page=\>5,:page=\>params[:software\_page]  
@document\_cis=DocumentCi.paginate  
per\_page=\>5,:page=\>params[:document\_page]

But this is not the way I think .Here i have three seperate pagination  
in view.That is not i want.How can I solve this?Please help

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [May 23, 2008, 8:19am UTC](https://www.ruby-forum.com/t/paginating-3-arrays-of-3-differnet-model/138455/2 "2008-05-23T08:19:55Z")

</div>

0-0-0-0-0-0-0-0-0-0-0  
Think Fool : Method 1  
0-0-0-0-0-0-0-0-0-0-0

@hardware\_cis=HardwareCi.find(:all)

@all\_data = [HardwareCi.find(:all), SoftwareCi.find(:all),  
DocumentCi.find(:all)]

@pages, @users = paginate\_collection @all\_data, :page =\> @params[:page]

private

#you can modify it  
def paginate\_collection(collection, options = {})  
default\_options = {:per\_page =\> 10, :page =\> 1}  
options = default\_options.merge options  
pages = Paginator.new self, collection.size, options[:per\_page],  
options[:page]  
first = pages.current.offset  
last = [first + options[:per\_page], collection.size].min  
slice = collection[first…last]  
return [pages, slice]  
end

x-x-x-x-x-x-x-x-x-x-x  
Think Fool : Method 2  
x-x-x-x-x-x-x-x-x-x-x

> @hardware\_cis=HardwareCi.paginate  
> per\_page=\>5,:page=\>params[:hardware\_page]  
> @software\_cis=SoftwareCi.paginate  
> per\_page=\>5,:page=\>params[:software\_page]  
> @document\_cis=DocumentCi.paginate  
> per\_page=\>5,:page=\>params[:document\_page]

@all\_data = []  
@all\_data \<\< @hardware\_cis  
@all\_data \<\< @software\_cis  
@all\_data \<\< @document\_cis

\<% for data in @all\_data %\>

Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)
