Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to render two paginated and ajaxable collections in the same view?
    primarykey
    data
    text
    <p>In a Rails 3.2 index view I am rendering two partials.</p> <pre><code>&lt;%= render :partial =&gt; 'users/user', :locals =&gt; {:users =&gt; @happy_users} %&gt; &lt;%= render :partial =&gt; 'users/user', :locals =&gt; {:users =&gt; @sad_users} %&gt; </code></pre> <p>and in the partial </p> <pre><code>&lt;% users.each do |user| %&gt; Show some fields &lt;% end %&gt; &lt;%= will_paginate users %&gt; </code></pre> <p>The pagination is not working. </p> <p>If I alter <code>will_paginate</code> to take an instance variable, pagination works (but the wrong collection)</p> <pre><code>&lt;%= will_paginate @users %&gt; </code></pre> <p>How can I pass locals to will_paginate when the partial is called?</p> <p>(I realize that I'll also need to pass <code>:param_name</code> to get this working with two collections. For now I'm just trying to get one instance working.)</p> <p>The partial is rendered via index.js.erb</p> <pre><code>$(".ajaxable-users").html('&lt;%= escape_javascript(render("users/user")) %&gt;'); </code></pre> <p>And the controller looks like</p> <pre><code>def index @users = User.scoped.paginate(:page =&gt; params[:page], :per_page =&gt; 5) @happy_users = User.happy_scope.paginate(:page =&gt; params[:page], :per_page =&gt; 5) @sad_users = User.happy_scope.paginate(:page =&gt; params[:page], :per_page =&gt; 5) respond_to do |format| format.html # index.html.erb format.xml { render :xml =&gt; @users } format.json { render :json =&gt; @users } format.js end end </code></pre> <p>Thanks for any ideas.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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