分页仅对特定查询不起作用 [英] Pagination not working only with a certain query
本文介绍了分页仅对特定查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Kaminari宝石通过Ajax进行分页
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)
,而上述实例变量的后两个正确运行.当我单击下一步按钮时,第一个出现,尽管我在Rails控制台中看到ajax请求发生,但它不会刷新页面.
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.
在我看来
<%= paginate @all_questions, :remote => true, :param_name => "unanswered" %>
<%= paginate @wrong, :remote => true, :param_name => "wrong_answers" %>
<%= paginate @answered, :remote => true, :param_name => "all_answered" %>
有人知道为什么吗?
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部分
@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 %>
推荐答案
您对应的 js.erb
可能看起来像这样:
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) %>');
这篇关于分页仅对特定查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文