我为收件箱和发送文件夹的邮件系统添加了无限滚动。但是,我无法将相同的代码应用于Users控制器和索引视图。有人可以帮忙吗?我从我的收件箱邮件系统中包含了工作代码。不知道我在为用户实现它时出错了。
用户控制器:
def index
@user = current_user
@users = @user.present? ? User.where('id != ?',@user.id) : User.all
render layout: 'new_application'
end
/users/index.html.slim:
#btm_container
.wrapper
.box_detail
= render collection: @users, partial: 'users/user', as: :user
对话控制器:
def index
@user = current_user
inbox_page = params[:page] if params[:inbox].present?
mailbox = @user.mailbox
@inbox = mailbox.inbox.paginate(:page => inbox_page, :per_page => 5)
render layout: 'new_application'
end
对话/ index.html.slim:
.wrapper
= render collection: @inbox, partial: 'conversations/conversation', as: :conversation
.hide#inbox_pagination
= will_paginate @inbox
javascript:
$(window).load(function(){
$("#send_trash").click(function(){
var ids = [];
$('input.conversation_checkbox:checked').each(function(){
ids.push($(this).data('id'));
});
$.ajax({ type: "POST", url:"/conversations/trash_all", data:{ids: ids}});
});
$('#inbox .pagination a').each(function(){
var href = $(this).attr('href')
if (href != 'undefined' && href != null) {
var link = href.split('?')
href = link[0]+'.js?'+link[1]
$(this).attr('href',href+'&inbox=true')
}
})
if ($('#inbox .pagination a').length > 0) {
$('#inbox').infinitescroll({
loading: {
msg: null,
msgText: "<em>Loading the next set of messages...</em>",
speed: 'fast',
},
finishedMsg: '<em> No More Messages </em>',
navSelector: 'div#inbox_pagination',
nextSelector: 'div#inbox_pagination a.next_page',
itemSelector: 'div#inbox div.outer',
debug: true,
appendCallback: true,
dataType: 'html',
errorCallback: function(data){console.log('data', data);},
prefill: false
},
function(){
$('input[type=checkbox]').jqTransCheckBox();
}
);
}
})