title: How make caching work with pagination and search form?
body: <p>I working with ruby on rails and my products views is cached and I can find products with search form. I want to use pagination as well, but when added, it didn't worked and also search form. Found code line ,but not sure how to use it, code below.</p>
  
  <pre><code>&lt;% cache ["v1-#{params[:page]-#{params[:q]", cache_key_for_products]
  &gt; do %&gt;
  </code></pre>
  
  <p>My code</p>
  
  <p><strong>Index.html.erb</strong></p>
  
  <pre><code>&lt;div class="products"&gt;
    &lt;div class="container"&gt;
      &lt;center&gt;&lt;h1&gt;All products&lt;/h1&gt;&lt;/center&gt;
      &lt;div class="row"&gt;
        &lt;% cache(cache_key_for_products) do %&gt;
        &lt;%= render @products %&gt;
        &lt;% end %&gt;
      &lt;/div&gt;
      &lt;%= will_paginate @comments, :container =&gt; false %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>_product.html.erb</strong></p>
  
  <pre><code>&lt;% cache product do %&gt;
  &lt;div class="col-md-3 col-lg-3 col-sm-6 col-xs-12"&gt;
    &lt;div class="product-block"&gt;
      &lt;h4 id="product-name"&gt;&lt;%= product.name %&gt;&lt;/h4&gt;
      &lt;%= link_to product_path(product), class: 'product_link' do %&gt;
        &lt;%= image_tag(product.image_url, class: "img-responsive") %&gt;
      &lt;% end %&gt;
      &lt;div class="price"&gt;
        &lt;h4&gt;&amp;pound; &lt;%= product.price %&gt;&lt;/h4&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>products_helper.rb</strong></p>
  
  <pre><code>module ProductsHelper
    def cache_key_for_products
      count          = Product.count
      max_updated_at = Product.maximum(:updated_at).try(:utc).try(:to_s, :number)
      "products/#{params[:q] || "all"}-#{count}-#{max_updated_at}#{signed_in? &amp;&amp; current_user.admin? ? "-admin" : "normal"}"
    end
  end
  </code></pre>
  
  <p><strong>products_controller.rb</strong></p>
  
  <pre><code>def index
      if params[:q].present?
        search_term = params[:q]
        if Rails.env.development?
          @products = Product.where("name LIKE ?", "%#{search_term}%")
        else
          @products = Product.where("name ilike ?", "%#{search_term}%")
        end
      else
        @products = Product.all.paginate(:page =&gt; params[:page], :per_page =&gt; 30)
      end
    end
  </code></pre>