# Will paginate question

**URL:** <https://www.ruby-forum.com/t/will-paginate-question/192458>\
**Category:** Ruby\
**Created:** [July 30, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/will-paginate-question/192458 "2010-07-30T16:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [July 30, 2010, 4:16pm UTC](https://www.ruby-forum.com/t/will-paginate-question/192458/1 "2010-07-30T16:16:37Z")

</div>

I have the following code:

```auto
@projetos = Array.new
 for permissao in @permissao
# @proj = Projeto.paginate :page => params[:page], :per_page => 10,
:order => "data_de_termino", :conditions => ["responsavel = ? or
responsavel_td = ? or coordenador = ? or id = ?", @usuario, @usuario,
@usuario, permissao.projeto.id]
    @proj = Projeto.paginate :page => params[:page], :per_page => 10,
:order => "data_de_termino", :conditions => ["id = ?",
permissao.projeto.id]
      for proj in @proj
        @projetos << proj
      end
 end
 @projetos.sort! { |a,b| a.data_de_termino <=> b.data_de_termino }
```

It lists @projetos just fine, but if i want to make a pagination of  
@projetos (to show 10 projetos per page)  
How can i do that in this case?  
'Cause @projetos will not be a Projeto.paginate, because @projetos  
allready is a array with everything I need.

---

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [July 30, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/will-paginate-question/192458/2 "2010-07-30T16:56:39Z")

</div>

Try this:

> **[Insight: Medical Device Software Articles and Resources](https://orthogonal.io/insights/)**
>
> Orthogonal provides timely news, literature reviews, articles, white papers, and commentary for a medical device manufacturing audience.

---

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [August 2, 2010, 2:02pm UTC](https://www.ruby-forum.com/t/will-paginate-question/192458/3 "2010-08-02T14:02:53Z")

</div>

I apreciate the aswer, but i was looking for a simplier solution… :\

Changing one line, of my previus code, to this:

@projetos = @projetos.paginate(:per\_page =\> 1, :page =\> params[:page])

It paginates, but when i go to other page it doesn’t show me what it  
should.  
Nether the pages.

---

<div class="post-metadata">

**Author:** ![upabibi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e19adc/32.png) [@upabibi](https://www.ruby-forum.com/u/upabibi)\
**Post date:** [August 3, 2010, 1:39pm UTC](https://www.ruby-forum.com/t/will-paginate-question/192458/4 "2010-08-03T13:39:28Z")

</div>

Got it.

I’ve found the problem.

I’ve trade

@proj = Projeto.paginate :page =\> params[:page], :per\_page =\> 10, :order  
=\> “data\_de\_termino”, :conditions =\> [“id = ?”, permissao.projeto.id]

for

@proj = Projeto.all(:order =\> “data\_de\_termino”, :conditions =\> [“id =  
?”, permissao.projeto.id])

I think that because of the first pagination, the second doesn’t works.

But even that way, I’ve done (just to make sure that will works) the  
line:

@projetos = Projeto.paginate :per\_page =\> 1, :page =\> params[:page],  
:conditions =\> [“id in (?)”, @projet.collect { |pro| pro.id }], :order  
=\> “data\_de\_termino”

This way, @projetos will be an Active Record object.

So, my final code is this way:

@projet = Array.new  
for permissao in @permissao  
@proj = Projeto.all(:order =\> “data\_de\_termino”, :conditions =\> [“id  
= ?”, permissao.projeto.id])  
for proj in @proj  
@projet \<\< proj  
end  
end  
@projetos = Projeto.paginate :per\_page =\> 1, :page =\> params[:page],  
:conditions =\> [“id in (?)”, @projet.collect { |pro| pro.id }], :order  
=\> “data\_de\_termino”
