# Fragment caching with search box

**URL:** <https://www.ruby-forum.com/t/fragment-caching-with-search-box/150064>\
**Category:** Rails\
**Created:** [October 3, 2008, 3:04am UTC](https://www.ruby-forum.com/t/fragment-caching-with-search-box/150064 "2008-10-03T03:04:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [October 3, 2008, 3:04am UTC](https://www.ruby-forum.com/t/fragment-caching-with-search-box/150064/1 "2008-10-03T03:04:05Z")

</div>

I’m trying to setup some fragment caching which works fine for the index  
but i’m not sure how to ignore the caching if they are searching the  
index results.

my code in short:

ItemsController

def index  
@items = Item.search(params[:search], params[:min\_rank],  
params[:max\_rank], params[:classification\_id], …)  
end

index.html.erb  
\<% cache (‘items’, {:page =\> params[:page] || 1}) do %\>  
\<% for item in @items %\>  
…show output  
\<% end %\>  
\<% end %\>

so my question is, what is the best way for me to ignore the caching in  
the index view if they enter a search term? maybe put an if statement  
to see if params[:search] is set?

how do you guys do this with multiple page views in the index with  
searching.
