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%>
<br/>
<div id="full_name">
<%= render :partial => "embaixada/cursos" , :locals => { :cursos
=> @cursos } %>
</div>
<br>
<span class="edit_link"><%= link_to "Adicionar novo
curso", :controller => "curso" , :action => "new" , :embaixada_id
=>@embaixada.id %></span>
<% end %>
PARTIAL:
<% if @cursos and not @cursos.empty? %>
<table class="curso" id="cursos">
<tr class="header">
<th>Curso</th><th>Dia Semana</th><th>Local</th> <th>Horário de
início</th> <th>Horário de fim</th> <th>Professor</th>
</tr>
<% @cursos.each do |curso| %>
<tr class="<%= cycle('odd', 'even') %>">
<td><%= link_to curso.nome, :controller => :curso, :action =>
"edit" ,:embaixada_id => @embaixada.id, :curso_id => curso.id %></td>
<td><%= curso.dia_semana.capitalize %></td>
...
...
...
</table>
<% end %>
<p>
<div style="font-size: small">
<%= will_paginate @cursos %>
</div>
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment