Rails action caching with querystring parameters

If you want to cache an action, based on all the query parameters (or say on nearly all of them), you can do:

caches_action :my_action, :cache_path => Proc.new { |c| c.params }

Or, maybe you want all but some params that you just use for Analytics (but that have no bearing on the records you’re fetching):

caches_action :my_action, :cache_path => Proc.new { |c| c.params.delete_if { |k,v| k.starts_with?('utm_') } }

Leave a Comment