我想通过Ajax应用多个分页与Kaminari现在这里是我的代码控制器
def user_note @user = current_user @notes = Bookmark.where('user_id = ? && note is not NULL',current_user.id).order('created_at DESC').page(params[:page_1]).per(4) @bookmarks = Bookmark.where('user_id = ? && note is NULL',current_user.id).order('created_at DESC').page(params[:page_2]).per(4) respond_to do |format| format.html format.xml{ render :xml => @user} end end
现在看到我有两个部分来渲染这个数组
<div id="bookmarks"> <%= render :partial =>"users/bookmark",:locals => { :bookmark => @bookmarks} %> </div> <%= paginate @bookmarks,:remote => true,:param_name => 'page' %>
内部部分是
<% bookmark.each do |bookmar| %> <%= render :partial => 'show_bookmark.html.erb',:locals => { :bookma => bookmar} %> <%end%>
$('#bookmarks').html('<%= escape_javascript render(:partial =>"users/bookmark",:locals => { :bookmark => @bookmarks}) %>'); $('#paginator').html('<%= escape_javascript(paginate(@bookmarks,:remote => true).to_s) %>');
你错过了这一行的参数
$('#paginator').html('<%= escape_javascript(paginate(@bookmarks,:remote => true).to_s) %>');
我认为应该是这样的
$('#paginator').html('<%= escape_javascript(paginate(@bookmarks,:param_name => 'page_2').to_s) %>');
你也在这一行传递错误的参数
<%= paginate @bookmarks,:param_name => 'page' %>
应该是这样的
<%= paginate @bookmarks,:param_name => 'page_2' %>
还请检查您是否将响应正确发送到JS文件.