Hi, I am using "will_paginate" for pagination. For that I have written following code. @selected_photos=BookPhoto.find(:all, :conditions=>["id=?", params[:id]]) @book_photos=@selected_photos.paginate :per_page => 3, :page => params[:page] It is working fine. I have problem with this that every time it is retrieving all records satisfying the where condition. I don''t want like that. It should fetch only three records from the database. How should I do that? Any help will be appreciated. Thanks, Tushar. -- Posted via http://www.ruby-forum.com/.
Hi Tushar, not very much sure but may be following line can solve your problem. BookPhoto.find(:all, :conditions=>["id=?",params[:id]]).paginate :per_page => 3, :page => params[:page] Sandip R~ On Tue, Jun 9, 2009 at 3:16 PM, Tushar Gandhi < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > I am using "will_paginate" for pagination. For that I have written > following code. > > @selected_photos=BookPhoto.find(:all, :conditions=>["id=?", > params[:id]]) > @book_photos=@selected_photos.paginate :per_page => 3, :page => > params[:page] > > It is working fine. > I have problem with this that every time it is retrieving all records > satisfying the where condition. > I don''t want like that. It should fetch only three records from the > database. > How should I do that? > > Any help will be appreciated. > > Thanks, > Tushar. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.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 -~----------~----~----~----~------~----~------~--~---
Hi Sandip, I think it will not solve my problem. It will again find all record and do paginate onto it. I don''t think so it will add any limit on the retrieval of records depending on the page. Any ways thanks for your quick reply. Thanks, Tushar Sandip Ransing wrote:> Hi Tushar, > > not very much sure but may be following line can solve your problem. > > BookPhoto.find(:all, :conditions=>["id=?",params[:id]]).paginate > :per_page > => 3, :page => params[:page] > > Sandip R~ > > On Tue, Jun 9, 2009 at 3:16 PM, Tushar Gandhi < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> It is working fine. >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Ruby on Rails Developer > http://sandip.sosblog.com > http://funonrails.wordpress.com > www.joshsoftware.com-- Posted via http://www.ruby-forum.com/.
On Jun 9, 11:12 am, Tushar Gandhi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi Sandip, > I think it will not solve my problem. It will again find all record and > do paginate onto it. I don''t think so it will add any limit on the > retrieval of records depending on the page. > Any ways thanks for your quick reply. > Thanks, > Tushar >It''s because you are doing a find and then paginating the resulting array. You should be doing something like BookPhoto.paginate(:conditions => ..., :page => params[:page], ...) Fred> > > > > Sandip Ransing wrote: > > Hi Tushar, > > > not very much sure but may be following line can solve your problem. > > > BookPhoto.find(:all, :conditions=>["id=?",params[:id]]).paginate > > :per_page > > => 3, :page => params[:page] > > > Sandip R~ > > > On Tue, Jun 9, 2009 at 3:16 PM, Tushar Gandhi < > > rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > >> It is working fine. > >> -- > >> Posted viahttp://www.ruby-forum.com/. > > > -- > > Ruby on Rails Developer > >http://sandip.sosblog.com > >http://funonrails.wordpress.com > >www.joshsoftware.com > > -- > Posted viahttp://www.ruby-forum.com/.
Thanks Frederick Your solution is what I am looking for. Thanks, Tushar Frederick Cheung wrote:> On Jun 9, 11:12�am, Tushar Gandhi <rails-mailing-l...@andreas-s.net> > wrote: >> Hi Sandip, >> I think it will not solve my problem. It will again find all record and >> do paginate onto it. I don''t think so it will add any limit on the >> retrieval of records depending on the page. >> Any ways thanks for your quick reply. >> Thanks, >> Tushar >> > > It''s because you are doing a find and then paginating the resulting > array. You should be doing something like > > BookPhoto.paginate(:conditions => ..., :page => params[:page], ...) > > Fred-- Posted via http://www.ruby-forum.com/.