Hi- Is it possible to use search parameters with will_paginate? For example, something like this: @var = Model.paginate :per_page => 20, :page => params[:page], :order => ''my_date DESC'', :conditions =>["my_date >= ? AND my_date <=?",@start,@end] I am getting some errors with this, but will this generally work? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you don''t get a suitable answer here, you should know that there is a will_paginate Google Group, just like this rubyonrails-talk group. Naturally, it''s called "will_paginate". :) n On Feb 19, 2008 12:38 PM, pete <peterbattaglia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi- > > Is it possible to use search parameters with will_paginate? > > For example, something like this: > > @var = Model.paginate :per_page => 20, :page => params[:page], > :order => ''my_date DESC'', :conditions > =>["my_date >= ? AND my_date <=?",@start,@end] > > I am getting some errors with this, but will this generally work?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I haven''t used the substitution like you have, but I can do it with a conditions hash: @items = Item.paginate(:all, :order => "featured DESC, #{@sort.sort}, id DESC", :conditions => @filters, :page => params[:page]) where @filters is a hash like {:hidden => false, :category_id => 5}. I notice that you don''t have an :all or :first at the beginning. Maybe this matters. -Kyle On Feb 19, 5:49 pm, "Nathan Fiedler" <nathanfied...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If you don''t get a suitable answer here, you should know that there is > a will_paginate Google Group, just like this rubyonrails-talk group. > Naturally, it''s called "will_paginate". :) > > n > > On Feb 19, 2008 12:38 PM, pete <peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi- > > > Is it possible to use search parameters with will_paginate? > > > For example, something like this: > > > @var = Model.paginate :per_page => 20, :page => params[:page], > > :order => ''my_date DESC'', :conditions > > =>["my_date >= ? AND my_date <=?",@start,@end] > > > I am getting some errors with this, but will this generally work?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Pete, Yes you can do conditional paginates. See my search method below. Note that you have to remember the search conditions between pages because you have to restate them on calls for subsequent pages. I stick mine in the session. Hope this helps, John def full_search unless params[:page] session[:search] = ["category_id = ? and address_posttown like ? and address_postcode like ? and published is true", params[:item][:category_id], (params[:item][:address_posttown].to_s) +"%", (params[:item][:address_postcode].to_s) +"%"] end @items = Item.paginate :page => params[:page], :conditions => session[:search] if @items.empty? flash.now[:error] = "Sorry, nothing matched your search request" end # old-fashioned reload for browsers not doing AJAX render :action => :search unless request.xhr? end -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---