# Will\_paginate

**URL:** <https://www.ruby-forum.com/t/will-paginate/132882>\
**Category:** Rails\
**Created:** [March 25, 2008, 3:03pm UTC](https://www.ruby-forum.com/t/will-paginate/132882 "2008-03-25T15:03:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [March 25, 2008, 3:03pm UTC](https://www.ruby-forum.com/t/will-paginate/132882/1 "2008-03-25T15:03:58Z")

</div>

hi at all  
I installed the plugin will\_paginate successfully and now I’ll use it.  
But I’ve a problem. I wrote a method search and this method return an  
array of products. The search method is special and not an easy find  
query. So I can use the :conditions of the will\_paginate plugin. But I  
will paginate the array of products.

So how I can use the will\_paginate plugin to group the products  
(:per\_page =\> 5 products).

thanks for helping…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [March 25, 2008, 10:09pm UTC](https://www.ruby-forum.com/t/will-paginate/132882/2 "2008-03-25T22:09:36Z")

</div>

But I’ve the problem, that I use acts\_as\_ferret for fulltext search. So  
I can’t use the :conditions statement in the paginate method. Because I  
have for example a query like ‘search ruby’. So i want to find records  
for ‘search ruby’, ‘search’ and ‘ruby’. So I call the find\_by\_content  
method from ferret three times. So I think, the paginate method is  
impractical, because I have the total\_hits as recently as after the  
three method calls.

Jesus bernardo Ruiz flores  
wrote:[http://www.ruby-forum.com/topic/147149?reply\_to=650959#postform](http://www.ruby-forum.com/topic/147149?reply_to=650959#postform)  
will\_paginate - Ruby Forum

> Here is an example of how i use will\_paginate to list 20 calls from page  
> and to change the conditions based on the restriction the user whan to  
> give:
> 
> def self.search(code,search,page)  
> if code.blank?  
> code=“DLXACCN”  
> end  
> paginate :per\_page=\>20, :page =\> page,  
> :conditions =\>[“#{code.upcase} like ?”,“%#{search}%”],  
> :order =\> “DLXDAT desc”  
> end
> 
> Code is the field that the user whan to check  
> search the value that the user is looking  
> page is the page number
> 
> And the controller look like this
> 
> def current\_calls  
> @dlxcurrent\_calls=DlxvcurrentCallsExt1.search(params[:code],params[:search],params[:page])  
> @sub\_title=“Detalle Llamadas Actuales”  
> @pagetitle=“Monitoreo Clientes VoIP”  
> respond\_to do |format|  
> format.html  
> format.xml {render :xml =\> @dlxcurrent\_calls}  
> end  
> end
> 
> Hope this help

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [March 25, 2008, 9:49pm UTC](https://www.ruby-forum.com/t/will-paginate/132882/3 "2008-03-25T21:49:41Z")

</div>

K. R. wrote:

> hi at all  
> I installed the plugin will\_paginate successfully and now I’ll use it.  
> But I’ve a problem. I wrote a method search and this method return an  
> array of products. The search method is special and not an easy find  
> query. So I can use the :conditions of the will\_paginate plugin. But I  
> will paginate the array of products.
> 
> So how I can use the will\_paginate plugin to group the products  
> (:per\_page =\> 5 products).
> 
> thanks for helping…

Here is an example of how i use will\_paginate to list 20 calls from page  
and to change the conditions based on the restriction the user whan to  
give:

def self.search(code,search,page)  
if code.blank?  
code=“DLXACCN”  
end  
paginate :per\_page=\>20, :page =\> page,  
:conditions =\>["#{code.upcase} like ?","%#{search}%"],  
:order =\> “DLXDAT desc”  
end

Code is the field that the user whan to check  
search the value that the user is looking  
page is the page number

And the controller look like this

def current\_calls  
@dlxcurrent\_calls=DlxvcurrentCallsExt1.search(params[:code],params[:search],params[:page])  
@sub\_title=“Detalle Llamadas Actuales”  
@pagetitle=“Monitoreo Clientes VoIP”  
respond\_to do |format|  
format.html  
format.xml {render :xml =\> @dlxcurrent\_calls}  
end  
end

Hope this help
