Pagination not working only with a certain query

若如初见. 提交于 2019-12-13 03:01:51

问题


I am using Kaminari gem to paginate using ajax

i have three paginations on the same page

    @all_questions = Question.where.not(id: current_user.question_ids).page(params[:unanswered]).per(1)

    @wrong = Tracker.where("user_id = ? AND correct = ?", current_user, false).page(params[:wrong_answers]).per(1)

    @answered = Tracker.where("user_id = ? AND answered = ?", current_user, true).page(params[:all_answered]).per(1)

while the last two of the above instance variables correctly work. The first one when i click the next button, while i see the ajax request happening in the rails console, it does not refresh the page.

in my view

<%= paginate @all_questions, :remote => true, :param_name => "unanswered" %>
<%= paginate @wrong, :remote => true, :param_name => "wrong_answers" %>
<%= paginate @answered, :remote => true, :param_name => "all_answered" %>

Anyone knows why?

html

     <section role="tabpanel" aria-hidden="true" class="content" id="panel2-2">
        <div class="row">
          <div class="large-10 large-offset-1 columns">
            <div class="panel questions-progress-panel">
              <ul>
                <div id="unanswered">
                  <%= render partial: "all_questions" %>
                </div>
                <div id="paginator4" class="text-center paginator">
                  <%= paginate @all_questions, :remote => true, :param_name => "unanswered" %>
                </div>
              </ul>
            </div>
          </div>
        </div>
      </section>

@all_questions partial

<% @all_questions.each do |q| %>
  <li>
    <div class="wrapper">
      <div class="row">
        <div class="large-8 medium-8 small-8 columns">
          <p class="question-title"> <%= q.description %> </p>
        </div>
        <div class="large-4 medium-4 small-4 columns text-right">
          <%= link_to "Go", category_question_path(q.category,q), class:"button round success" %>
        </div>
      </div>
    </div>
  </li>
<% end %>

回答1:


Your corresponding js.erb could look like this:

$('#unanswered').html('<%= escape_javascript render(all_questions) %>');
$("#paginator4").html('<%= escape_javascript(paginate(@all_questions, :remote => true).to_s) %>');


来源:https://stackoverflow.com/questions/36496370/pagination-not-working-only-with-a-certain-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!