John Small
2008-Nov-24 22:25 UTC
mislav-will_paginate & complicated SQL made up from params
I have a search form which sends a set of params to a controller. The params are unpacked and SQL generated which is then fed into (1) MyModel.paginate_by_sql [sql],:page => params[:page], :per_page => 30 Which all works fine and lovely, on the first page.. The links in each of the visible page buttons simply point to /controller/search_action?page=2 or 3 & so on. All the params used to create the sql are missing. So when the call comes in for the next page, only clean no selection sql is generated and I get the second (or third & etc) page of the entire data set, not the sub-set selected by the form. When I do this by (2) AnOtherModel.find_with_ferret params[:search_for], {:page=>params[:page], :per_page => 30} then search_for=something is added to the params list attached to the pagination links, so I can page back and forth in a search result set. So that works OK. How do I get the params for my query in (1) to be added to the pagination links so I get the params back to redo the query for the next page? -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-24 23:21 UTC
Re: mislav-will_paginate & complicated SQL made up from params
On Nov 24, 10:25 pm, John Small <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a search form which sends a set of params to a controller. The > params are unpacked and SQL generated which is then fed into > (1) > MyModel.paginate_by_sql [sql],:page => params[:page], :per_page => 30 > > Which all works fine and lovely, on the first page.. > > The links in each of the visible page buttons simply point to > /controller/search_action?page=2 or 3 & so on. All the params used to > create the sql are missing. So when the call comes in for the next page, > only clean no selection sql is generated and I get the second (or third > & etc) page of the entire data set, not the sub-set selected by the > form. > > When I do this by > (2) > AnOtherModel.find_with_ferret params[:search_for], > {:page=>params[:page], :per_page => 30} > > then search_for=something is added to the params list attached to the > pagination links, so I can page back and forth in a search result set. > So that works OK. > > How do I get the params for my query in (1) to be added to the > pagination links so I get the params back to redo the query for the next > page?Well you can always add params, it''s one option that you pass to the will_paginate method. If the request being handled is a get then the params that made up that request will be added automatically too. Fred> -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Small
2008-Nov-25 13:26 UTC
Re: mislav-will_paginate & complicated SQL made up from params
> Well you can always add params, it''s one option that you pass to the > will_paginate method. If the request being handled is a get then the > params that made up that request will be added automatically too. > > FredFred, Thanks for that. I was doing an unusual search such that a method=''post'' was being generated even though the resource path was a get. I was feeding an object into the form_for helper which made it think it had to do a post. The reason for feeding an object into the form_for helper is that I wanted an easy way to select various drop down boxes used in the search, so I''d created a temporary object on the fly, packed the parameters from the search into that object, and sent it back to the browser. This meant that if part of the search was made by selecting a country from a list, then when the new page was generated the selection would still be on that country. Anyway I got round it by setting :html=>{:method=>''get''} Thanks -- 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 -~----------~----~----~----~------~----~------~--~---