# Problem with will\_paginate and total\_pages

**URL:** <https://www.ruby-forum.com/t/problem-with-will-paginate-and-total-pages/149624>\
**Category:** Rails\
**Created:** [September 26, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/problem-with-will-paginate-and-total-pages/149624 "2008-09-26T21:08:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 26, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/problem-with-will-paginate-and-total-pages/149624/1 "2008-09-26T21:08:34Z")

</div>

I think I am observing a bug with the total\_pages count returned from  
my will\_paginate collection. Or, is there some other page count I can  
use that is more reliable?

I have a paginated list with a search box that is used to filter the  
list. The search string generates a :conditions clause that is used  
to narrow the list.

My problem is that the paginate collection.total\_pages count is  
incoreect. It reflects the size of the collection before  
the :conditions. Here is the code:

```
args = { :page => params[:page], :per_page => 10, :order => "id

```

desc" }  
if params[:file\_filter]  
args[:conditions] = [“file\_fullpath LIKE ?”,  
“%#{params[:file\_filter]}%”]  
end  
@files = @job.files.paginate(args)

The really annoying thing is the will\_paginate view helper knows the  
truth and generates the page number links correctly. Looking at the  
code it appears that the link renderer is using total\_pages. But when  
I access it from my code it returns the too-large value.
