问题
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