# Will\_paginate with conditions

**URL:** <https://www.ruby-forum.com/t/will-paginate-with-conditions/128952>\
**Category:** Rails\
**Created:** [February 12, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/will-paginate-with-conditions/128952 "2008-02-12T22:45:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@johnlester](https://www.ruby-forum.com/u/johnlester)\
**Post date:** [February 12, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/will-paginate-with-conditions/128952/1 "2008-02-12T22:45:00Z")

</div>

Hi, I’ve just switched to will\_paginate, which is impressive and easy to  
use!

I have a question regarding conditions:

I build a query using values from the params that were entered onto a  
web form using something like

:conditions =\> [" foo like x and bar like y", params[:x]+"%",  
params[:y]+"%"]

It would appear that the conditions need to be respecified on each page  
so I have had to remember them in the session:

unless params[:page]  
session[:search] = [“category\_id = ? and foo like ?  
and bar like ?”,  
params[:item][:category\_id],  
params[:item][:foo]+"%",  
params[:item][:bar]+"%"]  
end  
@items = Item.paginate :page =\> params[:page],  
:conditions =\> session[:search]

This works, but have I got it right, or is there a better way?
