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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
On 31 January 2012 12:16, Pedro <pogermano-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Jan 31, 10:33 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 31 January 2012 12:16, Pedro <pogerm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Hi Guys, In my application I created this method: def self.find_paginated_posts_by_post_type(post_type,page=1,query="") if query.empty? == false query = "%#{query}%" else query = "%" end result = includes(:user). where([''post_type_id = ? AND title LIKE ?'', post_type.id, query]). order(''created_at DESC''). page(page) return result end this method is returning an ActiveRecord::Relation Object. So, when I use will_paginate method my application throws an exception : undefined method `total_pages'' for #<ActiveRecord::Relation:0x007f94581e7848> How can I fix it? Thx Bruno Meira -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 9, 2012, at 5:11 PM, Bruno Meira wrote:> Hi Guys, > In my application I created this method: > > def self.find_paginated_posts_by_post_type(post_type,page=1,query="") > if query.empty? == false > query = "%#{query}%" > else > query = "%" > end > result = includes(:user). > where([''post_type_id = ? AND title LIKE ?'', post_type.id, query]). > order(''created_at DESC''). > page(page) > return result > end > > > this method is returning an ActiveRecord::Relation Object. So, when I use > will_paginate method my application throws an exception : > > undefined method `total_pages'' for #<ActiveRecord::Relation:0x007f94581e7848> > > How can I fix it? > ThxIf you add to_a to the end of the request, before you pass it to paginate, then all of the results will be queried and returned as an array -- old-school. But if you use Kaminari or another pagination system that works natively with ActiveRecord::Relation objects, you won''t have this issue (and you will get the benefits of Arel and all the wonder that is Rails 3+). Walter> > Bruno Meira > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Hi Walter, I will take a look in this solution and in this Kamirami Thx for the answer ;D -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
First time using Kaminari... But it seems to be a good gem. Thx for the tip ;D -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.