Will paginate question

I have the following 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 }

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.

Try this:

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

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.

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”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs