# Retireving record for will\_paginate

**URL:** <https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828>\
**Category:** Rails\
**Created:** [June 9, 2009, 11:46am UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828 "2009-06-09T11:46:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 9, 2009, 11:46am UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828/1 "2009-06-09T11:46:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 9, 2009, 11:52am UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828/2 "2009-06-09T11:52:05Z")

</div>

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 G. \<  
removed\_email\_address@domain.invalid\> wrote:

> ## It is working fine.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ruby on Rails Developer

> **[Blogs - Neuigkeiten - Artikel - Webseiten - Medien](https://www.sosblog.com/)**
>
> Auf SOSblog geht es um aktuelle Blogs, Neuigkeiten, Artikel, Webseiten und Medien. Wir bringen interessante neue Webseiten aus den Tiefen des Webs.

> **[Judul Situs](https://funonrails.wordpress.com/)**
>
> “Cinta tidak mengenal batas. Cinta mampu melewati rintangan, melompati pagar, menembus dinding untuk mencapai tujuannya dengan penuh harapan.” — Maya Angelou

> **[Josh Software | Custom Software Development Services & Solutions](https://joshsoftware.com/)**
>
> JoshSoftware offers custom software development Services & Solution that provides enterprise, software development services for web & mobile.

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 9, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828/3 "2009-06-09T12:12:18Z")

</div>

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 R. 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 G. \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > ## It is working fine.
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Ruby on Rails Developer  
> [http://sandip.sosblog.com](http://sandip.sosblog.com)  
> [http://funonrails.wordpress.com](http://funonrails.wordpress.com)  
> [www.joshsoftware.com](http://www.joshsoftware.com)

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 9, 2009, 12:48pm UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828/4 "2009-06-09T12:48:57Z")

</div>

On Jun 9, 11:12 am, Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![gandhi-tush](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5daacb/32.png) [@gandhi-tush](https://www.ruby-forum.com/u/gandhi-tush)\
**Post date:** [June 9, 2009, 1:21pm UTC](https://www.ruby-forum.com/t/retireving-record-for-will-paginate/169828/5 "2009-06-09T13:21:03Z")

</div>

Thanks Frederick  
Your solution is what I am looking for.  
Thanks,  
Tushar

Frederick C. wrote:

> On Jun 9, 11:12ï¿½am, Tushar G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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
