Hello Guys
I hope someone can help me
I've been trying but without success to do a pagination using the
will_paginate gem.
When I'm listing all records the system paginates but when I'm doing a
filter to show some records, just show the first five. Someone knows
whats happening?
My code
CONTROLLER
def index
@contract = Contract.new(params[:contract])
page = (params[:page] ||= 1).to_i
@contracts = Contract.search_index({:page => page})
@legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA,
NM_PESSOA", :joins => [:person])
@persons = Person.all
respond_to do |format|
format.html # index.html.erb
end
end
def list
@contract = Contract.new(params[:contract])
page = (params[:page] ||= 1).to_i
@contracts = Contract.find_by_params(params[:contract])
@legal_entities = LegalEntity.all(:select => "CD_PESSOA_JURIDICA,
NM_PESSOA", :joins => [:person])
@person = Person.all
render :index
end
VIEW
<% form_for(@contract, :url => { :action => "list"}, :onKeyPress =>
"submit();" ) do |f| %>
<!-- Início da Tabela de Filtro -->
<table class="Cabecalho" border="0">
<thead>
<tr>
<td colspan="4" class="titulos">Empresa:<br/>
<%= select(:contract, :CD_PESSOA_JURIDICA,
@legal_entities.collect{ |p| [
p.NM_PESSOA, p.CD_PESSOA_JURIDICA]},
{ :include_blank => true }) %>
</td>
</tr>
<tr>
<td width="30%" class="titulos">Número do contrato:<br/>
<%= f.text_field(:CD_CONTRATO, :style=>"width: 90%;",
:maxlength=>"7", :onKeypress => "apenasnum(this);")%>
</td>
<td width="20%"class="titulos">Ano:<br/>
<%= f.text_field(:NO_ANO, :style=>"width: 90%;", :onKeypress =>
"apenasnum(this);")%>
</td>
<td width="40%"class="titulos">Objeto do contrato:<br/>
<%= f.text_field(:DS_OBJETO_CONTRATO, :style=>"width: 80%;",
:onKeypress => "apenastex(this);")%>
</td>
<td width="9%" align="right" style="padding-right:35px;">
<%= image_submit_tag("lupa.png", :title => "Pesquisar")%>
</td>
</tr>
</thead>
</table>
<br/>
<div class="tab_botao">
<%= link_to ( image_tag("incluir.jpg",:style=>"width: 16px;
heigth:16px; border:0", :title =>"Incluir Novo"))+' Incluir Novo',
new_contract_path %>
</div>
<% if @contracts.empty? %>
<div class="div_registro">
<p>Nemhum contrato foi encontrado</p>
</div>
<% else %>
<table cellpadding="0" cellspacing="1" class="Cabecalho">
<thead>
<tr class="Cabecalho_bg">
<th align="left" style="padding-left: 5px;">Numero Contrato</th>
<th align="left" style="padding-left: 5px;">Ano</th>
<th align="left" style="padding-left: 5px;">Empresa</th>
<th align="left" style="padding-left: 5px;">Objeto</th>
<th align="left" style="padding-left: 5px;">Termo Aditivo</th>
</tr>
</thead>
<tbody class="zebra">
<% @contracts.each do |contract| %>
<tr>
<td style="padding-left:5px;"><%= link_to
contract.CD_CONTRATO, contract %></td>
<td style="padding-left:5px;"><%= contract.NO_ANO %></td>
<td style="padding-left:5px;" ><%=
contract.legal_entity.person.NM_PESSOA %></td>
<td style="padding-left:5px;"><%=
contract.DS_OBJETO_CONTRATO %></td>
<td style="padding-left:5px;"><b><%=
"#{contract.additiv_contracts.size} aditivos" %></b></td>
</tr>
<% end %>
</tbody>
<tr class="Cabecalho_bg">
<td colspan="6" class="Result">
Total de <b><%= @contracts.total_entries %></b> ítens.
</td>
</tr>
<tr>
<td colspan="6" class="paginacao">
<%= will_paginate @contracts %>
</td>
</tr>
</table>
<% end %>
<% end %>
Cheers
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.