From: Bla ... on
I have the following code:

[code]
@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 }
[/code]

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.
--
Posted via http://www.ruby-forum.com/.

From: Eugen Ciur on
Try this:

http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/

On 07/30/2010 05:16 PM, Bla ... wrote:
> I have the following code:
>
> [code]
> @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 }
> [/code]
>
> 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.
>

From: Bla ... on
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.
--
Posted via http://www.ruby-forum.com/.

From: Bla ... on
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"
--
Posted via http://www.ruby-forum.com/.