title: Calculated values from data returned by Ransack are removed when paginating with Kaminari
body: <p>On my Rails application, I am performing calculations on the data returned by Ransack. These are:</p>
  
  <ul>
  <li>Total count </li>
  <li>Averages on certain fields</li>
  </ul>
  
  <p>The averages work but as soon as I go to the next page (using Kaminari pagination) the values disappear. However, total count continues to work.</p>
  
  <p>From the view, this works:</p>
  
  <pre><code>&lt;%= @products.total_count %&gt;
  </code></pre>
  
  <p>Also from the view, this works, but when going to the next page, it doesn't:</p>
  
  <pre><code>&lt;%= number_to_percentage(@products.average(:status), precision: 0) %&gt;
  </code></pre>
  
  <p>Does anyone have any ideas?</p>
  
  <p>Products controller:</p>
  
  <pre><code>def index
      @q = Product.ransack(params[:q])
      @q.sorts = 'start_date desc' if @q.sorts.empty?
      @products = @q.result.page(params[:page]).per(30)
  end
  </code></pre>
  
  <p>This is the SQL query from when it works on the first page:</p>
  
  <pre><code>(23.7ms)  SELECT  AVG("products"."price_eur") AS avg_id FROM "products"  WHERE (status &gt; 100) AND "products"."above_revenue_average" = 't' AND ("products"."name" ILIKE '%a%') LIMIT 30 OFFSET 0
  </code></pre>
  
  <p>And the params:</p>
  
  <pre><code>Parameters: {"utf8"=&gt;"✓", "q"=&gt;{"name_cont"=&gt;"a", "type_eq"=&gt;"", "upward_trending"=&gt;"1", "downward_trending"=&gt;"", "category_id_in"=&gt;[""], "country_eq"=&gt;"", "price_eur_gteq"=&gt;"", "price_eur_lteq"=&gt;"", "start_date_gteq"=&gt;"", "start_date_lteq"=&gt;""}, "commit"=&gt;"All"}   
  </code></pre>
  
  <p>This is the SQL query from when it stops working on the second page:</p>
  
  <pre><code>(23.8ms)  SELECT  AVG("products"."price_eur") AS avg_id FROM "products"  WHERE (status &gt; 100) AND "products"."above_revenue_average" = 't' AND ("products"."name" ILIKE '%a%')
  </code></pre>
  
  <p>And the params:</p>
  
  <pre><code>Parameters: {"commit"=&gt;"All", "page"=&gt;"2", "q"=&gt;{"category_id_in"=&gt;[""], "country_eq"=&gt;"", "downward_trending"=&gt;"", "name_cont"=&gt;"a", "price_eur_gteq"=&gt;"", "price_eur_lteq"=&gt;"", "start_date_gteq"=&gt;"", "start_date_lteq"=&gt;"", "type_eq"=&gt;"", "upward_trending"=&gt;"1"}, "utf8"=&gt;"✓"}   
  </code></pre>