I have this in my application_helper.rb
def cache_unless( condition, name = {}, options = nil, &block)
cache_if( !condition, name, options, &block)
end
def cache_if( condition, name = {}, options = nil, &block)
if condition
cache(name, options, &block)
else
yield
end
end
so now in my view I can do something like
<% cache_unless (params[:search], ''items'', {:page =>
params[:page] ||
1}) do %>
<% for item in @items %>
...show output
<% end %>
<% end %>
On Oct 2, 6:04 pm, Scott Kulik
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---