Will paginate question

B

Bla ...

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 }

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.
 
B

Bla ...

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.
 
B

Bla ...

Got it.

I've found the problem.

I've trade

@proj = Projeto.paginate :page => params[:page], :per_page => 10, :eek:rder
=> "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 } ], :eek:rder
=> "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 } ], :eek:rder
=> "data_de_termino"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top