通过Ajax多个分页与雷 [英] Multiple pagination with kaminari via Ajax

查看:112
本文介绍了通过Ajax多个分页与雷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Ajax应用多个分页与雷喏,这就是我的$ C $下控制器

I want to apply multiple pagination with Kaminari via Ajax now here is my code for controller

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

现在的观点我有两个谐音来呈现这个阵

now for views i have two partials to render this arrays

<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%>

分页更新脚本是在一个单独的文件正在办理

script for pagination update is being handled in a separate file

$('#bookmarks').html('<%= escape_javascript render(:partial =>"users/bookmark",:locals => { :bookmark => @bookmarks}) %>');
$('#paginator').html('<%= escape_javascript(paginate(@bookmarks, :remote => true).to_s) %>');

但是这样做的每一件事它不更新页面的状态,无论是包含在页面中。

But by doing every thing it is not updating to state of page neither the contain in the page.

推荐答案

你缺少到该行通过PARAMS

you are missing to pass params at this line

$('#paginator').html('<%= escape_javascript(paginate(@bookmarks, :remote => true).to_s) %>');

我想应该是这样的。

i think it should be like this

$('#paginator').html('<%= escape_javascript(paginate(@bookmarks, :remote => true, :param_name => 'page_2').to_s) %>');

和你也传递错误的参数在该行

and you are also passing wrong param at this line

<%= paginate @bookmarks,:remote => true, :param_name => 'page' %>

就应该是这样的。

it should be like this

<%= paginate @bookmarks,:remote => true, :param_name => 'page_2' %>

和也请检查您是否正确发送响应JS文件与否。

and please also check that whether you are sending the response correctly to the JS file or not.

这篇关于通过Ajax多个分页与雷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆