我想用 Kaminari 创建一个“加载更多”的 ajax 分页。我正在使用这段代码:
class BienvenueController < ApplicationController
def index
@articles = Admin::Article.page(1).per(2)
respond_to do |format|
format.html
format.js
end
end
end
# Bienvenue#index
<div class="container" style="min-width:<%= @width %>px">
<%= render "shared/articles" %>
<%= link_to_next_page @articles, 'Load More', :remote => true, :id=>"load_more_link" %>
# Shared/articles
<% @articles.each do |a| %>
<article class="<%= a.rubrique.color %>">
<div class="sharing">
<%= image_tag "facebook-32.png" %>
</div>
<p class="color<%= a.rubrique.color %>"><i>Le <%= I18n.localize(a.created_at, :format => :long) %> par David Perrotin</i></p>
<h1><%= a.titre %></h1>
<div class="excerpt">
<%= a.chapo.html_safe %>
</div>
<div class="image">
<%= image_tag a.mainphoto.url(:medium), :width=>"100%" %>
</div>
<div class="contenu">
<%= a.contenu.html_safe %>
</div>
<div class="readmore">
<%= link_to "Continuer la lecture", article_path(a) %>
</div>
</article>
<% end %>
# index.js.erb
$('.container').append("<%= escape_javascript(render 'shared/articles')%>");
$('#load_more_link').replaceWith("<%= escape_javascript(link_to_next_page(@articles, 'Load More', :remote => true, :id=>'load_more_link'))%>");
但问题是,当我点击“加载更多”时,它总是显示两篇相同的文章,部分内容永远不会再刷新两篇文章,就像我想要的那样。