0
我在Rails 4應用程序中使用Kaminari和AJAX。到目前爲止,我已經能夠爲第一頁顯示不同數量的記錄(13),但之後在每個頁面的14條記錄中顯示AJAX。這或多或少地完美。Rails 4:Kaminari - 顯示重複項
然而,當我設置的第一頁記錄數是一個更大的數字,比如說27,雷開始在已經顯示在第27位
在我開發應用程序重複加載,我總共只有30條記錄。第一頁確實顯示27,並且第2頁應該只顯示3,但是在顯示另一頁上的最後3頁之前,它從第一頁顯示14個副本。
有誰知道它爲什麼會加載重複而不是僅顯示頁面2的最後3個?
PagesController.rb>索引
@dabbles = Dabble.where(:completed_upload => true, :sketch => false).order('created_at DESC')
@dabbles = Kaminari.paginate_array(@dabbles)
@page = (params[:page] || '1').to_i
if @page == 1
@dabbles = @dabbles.page(params[:page]).per(27)
else
@dabbles = @dabbles.page(params[:page]).per(14)
end
respond_to do |format|
format.html
format.js
format.json
end
index.html.erb
<div class="grid" id="fresh">
<%= render :partial => 'pages/hexagons', :locals => { :dabbles => @dabbles, :count => 1 } %>
</div>
<div id="corrections" style="display: inline;">
<!-- irrelevant. -->
</div>
<div id="paginator">
<%= link_to_next_page @dabbles, 'Load More', :remote=>true %>
</div>
index.js.erb的
$('#fresh').append("<%= escape_javascript render :partial => 'pages/hexagons', :locals => { :dabbles => @dabbles, :count => 0 } %>");
$('#corrections').append("<%= escape_javascript render :partial => 'pages/corrections', :locals => { :correction => correct_helper(@dabbles.size) } %>");
$('#paginator').html("<%= escape_javascript(link_to_next_page @dabbles, 'Load More', :remote=>true) %>");