Will_paginate

I’m using will_paginate on my app and it’s working fine. The problem
came when I had to put search field.
After the search, the first page comes according to the parameter
passed, but when I go to the second page, it don’t brings me the
second page, but a new search with no search parameter restriction. I
tried everything, but didn’t work. Could somebody help me?

Thanks,

Pedro

Gemfile:

gem “rails”, “2.3.8”
gem “will_paginate”, “2.3.15”

CONTROLLER:

@cursos = Curso.paginate :per_page => 12, :page =>
params[:page], :conditions => [‘nome like ?’, “%#{params[:search]}
%”], :order =>‘nome, dia_semana’

VIEW:

<% tabnav :embaixada do %>
<% form_tag :url => ‘/embaixada/cursos’, :method => ‘get’ do %>
<%= text_field_tag :search, params[:search], :value => nil %>
<%= submit_tag “Busca”, :name => nil , :disable_with =>
“Aguarde…”%>
<%end%>

<%= render :partial => "embaixada/cursos" , :locals => { :cursos => @cursos } %>

<%= link_to "Adicionar novo curso", :controller => "curso" , :action => "new" , :embaixada_id =>@embaixada.id %> <% end %>

PARTIAL:

<% if @cursos and not @cursos.empty? %>

<% @cursos.each do |curso| %> ... ... ...
Curso Dia Semana Local Horrio de incio Horrio de fim Professor
<%= link_to curso.nome, :controller => :curso, :action => "edit" ,:embaixada_id => @embaixada.id, :curso_id => curso.id %> <%= curso.dia_semana.capitalize %>
<% end %>

<%= will_paginate @cursos %>

On 31 January 2012 12:16, Pedro [email protected] wrote:

I’m using will_paginate on my app and it’s working fine. The problem
came when I had to put search field.
After the search, the first page comes according to the parameter
passed, but when I go to the second page, it don’t brings me the
second page, but a new search with no search parameter restriction. I
tried everything, but didn’t work. Could somebody help me?

Have a look in log/development.log to give you some clues as to what
is happening.
If you still can’t work it out have a look at the Rails Guide on
Debugging. In particular see how to use ruby-debug to break into your
code and inspect data and follow the flow to see what is going wrong.

Colin

Hi Colin,

I found the problem, :params wasn’t present on partial, so I did it:

<%= will_paginate @cursos , :previous_label => h("<"), :next_label =>
h(">"), :params => { “controller”=>“embaixada”,“action”=>“cursos”,
“search”=> params[:search]} %>

Thanks!

Pedro

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