Hello G.s
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| %>
Empresa: <%= select(:contract, :CD_PESSOA_JURIDICA, @legal_entities.collect{ |p| [ p.NM_PESSOA, p.CD_PESSOA_JURIDICA]}, { :include_blank => true }) %> |
|||
Número do contrato: <%= f.text_field(:CD_CONTRATO, :style=>"width: 90%;", :maxlength=>"7", :onKeypress => "apenasnum(this);")%> |
Ano: <%= f.text_field(:NO_ANO, :style=>"width: 90%;", :onKeypress => "apenasnum(this);")%> |
Objeto do contrato: <%= f.text_field(:DS_OBJETO_CONTRATO, :style=>"width: 80%;", :onKeypress => "apenastex(this);")%> |
<%= image_submit_tag("lupa.png", :title => "Pesquisar")%> |
<% if @contracts.empty? %>
Nemhum contrato foi encontrado
Numero Contrato | Ano | Empresa | Objeto | Termo Aditivo | <%= contract.NO_ANO %> | <%= contract.legal_entity.person.NM_PESSOA %> |
<%= contract.DS_OBJETO_CONTRATO %> |
<%= “#{contract.additiv_contracts.size} aditivos” %> |
---|---|---|---|---|
Total de <%= @contracts.total_entries %> ítens. |
Cheers