Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like will_paginate imposes its own <code>limit</code> clause on your relation in order to do the paging. After some experimentation, the easiest way I could find to do this is to do eager-loading of the result set and use the functionality contained in <a href="https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/array.rb#files" rel="noreferrer">the array extensions</a> to do the actual pagination.</p> <p>Here's a quick example; note that you have to require <code>will_paginate/array</code>; you may wish to do this in an initializer or somewhere else. Note that it does monkey-patch <code>Array</code> to have the <code>paginate</code> method.</p> <pre><code>require 'will_paginate/array' class ArticlesController &lt; ApplicationController def index @articles = Article.published.limit(20).all # call `all` to eager load @articles = @articles.paginate(:page =&gt; params[:page], :per_page =&gt; 10) end end </code></pre> <p><strong>[Update]</strong></p> <p>Another option is to pass in the <code>total_entires</code> option to will_paginate based on the result set size.</p> <pre><code>class ArticlesController &lt; ApplicationController def index @articles = Article.published.limit(20) @articles = @articles.paginate(:page =&gt; params[:page], :per_page =&gt; 10, :total_entries =&gt; @articles.count) end end </code></pre> <p>You can't pass in 20 as you can't guarantee that a full 20 results will be returned; by passing in the <code>count</code> attribute, you can ensure that the pagination will be correct.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload