我对索引进行了无休止的滚动,数据库中有超过200个用户。它的设置是每页显示四个用户,我可以向下滚动的页面数是6.有人知道它为什么没有加载其他页面吗?
用户控制器:
def index
@user = current_user
@search = Search.new
page = params[:page] || 1
@order = params[:order] || ['age', 'created_at', 'birthday', 'username'].shuffle.first
if @user.present?
@users = User.search(:without => {:user_id => @user.id}, :page => page, :per_page => 4, :order => "#{@order} DESC")
else
@users = User.search(:page => page, :per_page => 4, :order => "#{@order} DESC")
end
@page = page
if request.xhr?
render :partial => 'user', :layout => false, :collection => @users
else
render layout: 'new_application'
end
end
日志报告:
Aug 01 09:44:01 website app/web.1: Started GET "/" for 84.53.163.847 at 2015-08-01 16:44:00 +0000
Aug 01 09:44:01 website app/web.1: Started GET "/" for 84.53.163.847 at 2015-08-01 16:44:00 +0000
Aug 01 09:44:01 website app/web.1: Processing by UsersController#index as HTML
Aug 01 09:44:01 website app/web.1: Processing by UsersController#index as HTML
Aug 01 09:44:01 website app/web.1: Rendered users/_user.html.slim (98.4ms)
Aug 01 09:44:01 website app/web.1: Rendered users/_user.html.slim (98.4ms)
Aug 01 09:44:01 website app/web.1: Rendered contacts/_form.html.slim (1.3ms)
Aug 01 09:44:01 website app/web.1: Rendered contacts/_form.html.slim (1.3ms)
Aug 01 09:44:01 website app/web.1: Rendered contacts/_form.html.slim (71.8ms)
Aug 01 09:44:01 website app/web.1: Rendered contacts/_form.html.slim (71.8ms)
Aug 01 09:44:01 website app/web.1: Rendered users/index.html.slim within layouts/new_application (184.9ms)
Aug 01 09:44:01 website app/web.1: Rendered users/index.html.slim within layouts/new_application (184.9ms)
Aug 01 09:44:01 website app/web.1: Rendered letsgos/_form.html.erb (1.1ms)
Aug 01 09:44:01 website app/web.1: Rendered letsgos/_form.html.erb (1.1ms)
Aug 01 09:44:01 website app/web.1: Rendered shared/_header.html.slim (13.6ms)
Aug 01 09:44:01 website app/web.1: Rendered shared/_header.html.slim (13.6ms)
Aug 01 09:44:01 website app/web.1: Completed 200 OK in 205ms (Views: 125.7ms | ActiveRecord: 76.5ms)
Aug 01 09:44:01 website app/web.1: Completed 200 OK in 205ms (Views: 125.7ms | ActiveRecord: 76.5ms)
Aug 01 09:44:01 website heroku/router: at=info method=GET path="/" host=website.com request_id=9ca1f8ad-e5f2-4711-a222-de8b5371df5b fwd="84.53.163.847" dyno=web.1 connect=1ms service=213ms status=200 bytes=27631
Aug 01 09:44:01 website heroku/router: at=info method=GET path="/assets/sbg4.jpg" host=website.com request_id=33d17a4f-ec69-417a-b9cd-faaddb830531 fwd="84.53.163.847" dyno=web.1 connect=2ms service=19ms status=200 bytes=347627
Aug 01 09:44:04 website heroku/router: at=info method=GET path="/users?page=2&order=age" host=website.com request_id=52e20cb4-b82a-4da7-a92b-c4db58606466 fwd="84.53.163.847" dyno=web.1 connect=3ms service=95ms status=200 bytes=5471
Aug 01 09:44:04 website app/web.1: Started GET "/users?page=2&order=age" for 84.53.163.847 at 2015-08-01 16:44:04 +0000
Aug 01 09:44:04 website app/web.1: Started GET "/users?page=2&order=age" for 84.53.163.847 at 2015-08-01 16:44:04 +0000
Aug 01 09:44:04 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:04 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:04 website app/web.1: Parameters: {"page"=>"2", "order"=>"age"}
Aug 01 09:44:04 website app/web.1: Parameters: {"page"=>"2", "order"=>"age"}
Aug 01 09:44:04 website app/web.1: Rendered users/_user.html.slim (76.8ms)
Aug 01 09:44:04 website app/web.1: Rendered users/_user.html.slim (76.8ms)
Aug 01 09:44:04 website app/web.1: Completed 200 OK in 90ms (Views: 33.2ms | ActiveRecord: 54.1ms)
Aug 01 09:44:04 website app/web.1: Completed 200 OK in 90ms (Views: 33.2ms | ActiveRecord: 54.1ms)
Aug 01 09:44:07 website app/web.1: Started GET "/users?page=3&order=age" for 84.53.163.847 at 2015-08-01 16:44:06 +0000
Aug 01 09:44:07 website heroku/router: at=info method=GET path="/users?page=3&order=age" host=website.com request_id=131a8cbc-54e8-43e4-9a4c-d7faf136fa5d fwd="84.53.163.847" dyno=web.1 connect=3ms service=107ms status=200 bytes=5527
Aug 01 09:44:07 website app/web.1: Started GET "/users?page=3&order=age" for 84.53.163.847 at 2015-08-01 16:44:06 +0000
Aug 01 09:44:07 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:07 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:07 website app/web.1: Parameters: {"page"=>"3", "order"=>"age"}
Aug 01 09:44:07 website app/web.1: Parameters: {"page"=>"3", "order"=>"age"}
Aug 01 09:44:07 website app/web.1: Rendered users/_user.html.slim (64.6ms)
Aug 01 09:44:07 website app/web.1: Rendered users/_user.html.slim (64.6ms)
Aug 01 09:44:07 website app/web.1: Completed 200 OK in 82ms (Views: 37.7ms | ActiveRecord: 42.6ms)
Aug 01 09:44:07 website app/web.1: Completed 200 OK in 82ms (Views: 37.7ms | ActiveRecord: 42.6ms)
Aug 01 09:44:09 website heroku/router: at=info method=GET path="/users?page=4&order=age" host=website.com request_id=2abbca51-b489-48fb-a8be-f31865ade053 fwd="84.53.163.847" dyno=web.1 connect=1ms service=116ms status=200 bytes=5527
Aug 01 09:44:09 website app/web.1: Started GET "/users?page=4&order=age" for 84.53.163.847 at 2015-08-01 16:44:09 +0000
Aug 01 09:44:09 website app/web.1: Started GET "/users?page=4&order=age" for 84.53.163.847 at 2015-08-01 16:44:09 +0000
Aug 01 09:44:09 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:09 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:09 website app/web.1: Parameters: {"page"=>"4", "order"=>"age"}
Aug 01 09:44:09 website app/web.1: Parameters: {"page"=>"4", "order"=>"age"}
Aug 01 09:44:09 website app/web.1: Rendered users/_user.html.slim (88.4ms)
Aug 01 09:44:09 website app/web.1: Rendered users/_user.html.slim (88.4ms)
Aug 01 09:44:09 website app/web.1: Completed 200 OK in 101ms (Views: 32.1ms | ActiveRecord: 66.2ms)
Aug 01 09:44:09 website app/web.1: Completed 200 OK in 101ms (Views: 32.1ms | ActiveRecord: 66.2ms)
Aug 01 09:44:11 website app/web.1: Started GET "/users?page=5&order=age" for 84.53.163.847 at 2015-08-01 16:44:10 +0000
Aug 01 09:44:11 website heroku/router: at=info method=GET path="/users?page=5&order=age" host=website.com request_id=e5e8fbc6-6b6b-4a91-982d-54944d2ca3e6 fwd="84.53.163.847" dyno=web.1 connect=1ms service=111ms status=200 bytes=5500
Aug 01 09:44:11 website app/web.1: Started GET "/users?page=5&order=age" for 84.53.163.847 at 2015-08-01 16:44:10 +0000
Aug 01 09:44:11 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:11 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:11 website app/web.1: Parameters: {"page"=>"5", "order"=>"age"}
Aug 01 09:44:11 website app/web.1: Parameters: {"page"=>"5", "order"=>"age"}
Aug 01 09:44:11 website app/web.1: Rendered users/_user.html.slim (92.2ms)
Aug 01 09:44:11 website app/web.1: Rendered users/_user.html.slim (92.2ms)
Aug 01 09:44:11 website app/web.1: Completed 200 OK in 104ms (Views: 31.7ms | ActiveRecord: 70.5ms)
Aug 01 09:44:11 website app/web.1: Completed 200 OK in 104ms (Views: 31.7ms | ActiveRecord: 70.5ms)
Aug 01 09:44:12 website heroku/router: at=info method=GET path="/users?page=6&order=age" host=website.com request_id=52fdfce3-576c-41d0-a711-af1173bb3528 fwd="84.53.163.847" dyno=web.1 connect=4ms service=133ms status=200 bytes=4321
Aug 01 09:44:12 website app/web.1: Started GET "/users?page=6&order=age" for 84.53.163.847 at 2015-08-01 16:44:12 +0000
Aug 01 09:44:13 website app/web.1: Started GET "/users?page=6&order=age" for 84.53.163.847 at 2015-08-01 16:44:12 +0000
Aug 01 09:44:13 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:13 website app/web.1: Processing by UsersController#index as */*
Aug 01 09:44:13 website app/web.1: Parameters: {"page"=>"6", "order"=>"age"}
Aug 01 09:44:13 website app/web.1: Parameters: {"page"=>"6", "order"=>"age"}
Aug 01 09:44:13 website app/web.1: Rendered users/_user.html.slim (97.4ms)
Aug 01 09:44:13 website app/web.1: Rendered users/_user.html.slim (97.4ms)
Aug 01 09:44:13 website app/web.1: Completed 200 OK in 124ms (Views: 38.7ms | ActiveRecord: 82.5ms)
Aug 01 09:44:13 website app/web.1: Completed 200 OK in 124ms (Views: 38.7ms | ActiveRecord: 82.5ms)
index.html.slim:
function getMoreRecords(){
var pageOffset = $('#more_users').val();
var order = "#{@order}";
$('#more_button').hide();
var url = "/users?"+"page=" + pageOffset + "&order=" + order;
$.ajax({
url: url,
method: 'GET',
success: function(html_data){
// make jQuery object from HTML string
var $moreBlocks = jQuery( html_data );
$moreBlocks.css('display','none');
$(".box_detail").append($moreBlocks).imagesLoaded(
function(){
$moreBlocks.fadeIn(1000);
$(".box_detail").masonry('appended', $moreBlocks);
isFetchingPics = false;
}
);
Cufon.refresh();
$( ".common_box" ).mouseenter(function() {
$(this).find(".btn_link").show();
}).mouseleave(function() {
$(this).find(".btn_link").hide();
});
if($moreBlocks.length == 4){
$('#more_users').val((parseInt(pageOffset) + 1));
$('#more_button').show();
}
$('.message_btn').magnificPopup();
$('.report_btn').magnificPopup();
$('.message_btn').click(function () {
var user_id = $(this).data('user');
$('#user').val(user_id);
var avatar_url = $("#image_" + user_id).attr('src');
var username = $("#name_" + user_id).val();
var age = $("#age_" + user_id).val();
var gender = $("#gender_" + user_id).val();
var sexuality = $("#sexuality_" + user_id).val();
var city = $("#city_" + user_id).val();
var state = $("#state_" + user_id).val();
var html_content = "<div class=\"commoon_sec\">" +
"<div class=\"left_sec\"><img alt=\"Popup baby\" src=\"" + avatar_url + "\"></div>" +
"<div class=\"right_sec\" style=\"position:relative;\">" +
"<div class=\"top_box\" style=\"position:absolute; border: 1px solid #cccccc; width: 456px; border-radius: 6px; height: 140px; background-color: #F7F7F7;\">" +
"<div class=\"left_box\" style=\"float:right; text-align:left; width: 68%;\">" +
"<h2>" + username + "</h2><h3>" + age + ", " + gender + ", " + sexuality + "</br>" +
city + ", " + state + "</h3></div></div></div></div>";
$("div.common_sec").html(html_content);
Cufon.refresh();
});
$('form#message_form').bind('ajax:success', function(evt, data, status, xhr){
$.magnificPopup.close()
});
$('.save_btn').magnificPopup();
}
});
}
$("#relegion, #gender, #children, #ethnicity").on('change', function(){
return false;
});
$("#basic_search input.text_input").on('keyup', function(){
$("input.adv_text_input").val(this.value);
});
$("#reset_form").on('click', function(){
$("form#adv_search").trigger('reset');
$("form#basic_search").trigger('reset');
$("input.adv_text_input").val("");
});
$("#basic_search").submit(function(e){
$('form#adv_search').submit();
e.preventDefault();
});
$("#save_search").on("click", function () {
$('form#adv_search').attr('action', "/searches/save_searches");
$('form#adv_search').submit();
e.preventDefault();
});
_user.html.slim:
- if user.avatar.present?
- style_class = {"1" => "box1", "2" => "box2", "3" => "box3", "4" => "box1"}
- style_type = {"1" => "similar", "2" => "profile", "3" => "box", "4" => "similar"}
- shuffle_array = ["1", "2", "3", "4"]
- my_index = shuffle_array.rotate(@page.to_i || ((user_counter+1).to_f/4.to_f).ceil)
- my_style = @page.present? ? style_type[my_index[user_counter]] : style_type[my_index[((user_counter+1).to_f%4.to_f).ceil]]
- my_style_class = @page.present? ? style_class[my_index[user_counter]] : style_class[my_index[((user_counter+1).to_f%4.to_f).ceil]]
div class="common_box #{my_style_class}" data-user-id="#{user.username}" id="#{user.username}"
.img_box
= link_to user do
= image_tag user.avatar.try(:image_url, my_style), id: "image_#{user.id}"
input type="hidden" id="name_#{user.id}" value="#{user.username}"
input type="hidden" id="age_#{user.id}" value="#{user.age}"
input type="hidden" id="gender_#{user.id}" value="#{user.gender}"
input type="hidden" id="sexuality_#{user.id}" value="#{user.sexuality}"
input type="hidden" id="city_#{user.id}" value="#{user.location.try(:city)}"
input type="hidden" id="state_#{user.id}" value="#{user.location.try(:state)}"
-if @user.present?
ul.btn_link.hide
li
a.message_btn href="#" data-user="#{user.id}" data-mfp-src='#message_me' Message
li id="set_follow_#{user.username}"
- if current_user.following?(user)
= link_to "UnFollow", users_set_follow_path(:id => user), class: 'users save_btn', remote: true
-else
= link_to "Follow", users_set_follow_path(:id => user), class: 'users save_btn', remote: true
li
a.report_btn href="#" data-mfp-src='#report_me' Report
.img_detail
small years
.circle
span.age_box class="#{user.gender == 'Male' ? '': 'pink'}" = user.age
h3 class="#{user.gender == 'Male' ? '' : 'pink'}" = user.username
h4
= user.address
div class= "#{user.gender == 'Male' ? 'green_corner': 'pink_corner'}"
=image_tag "#{user.gender == 'Male' ? 'side_curv.png': 'curv_2.png'}"
答案 0 :(得分:4)
这是关闭主题。这不是一个JavaScript问题。我回滚了heroku,删除了添加到数据库的最后10个用户,一切都很好。从未能找到罪魁祸首,但所提供的答案都不合适。
感谢您的帮助!
答案 1 :(得分:1)
在你的AJAX调用中,尝试将参数(页面,顺序)作为数据对象传递,而不是像这样传递url的一部分:
$.ajax({
url: url,
data: {page: PAGE_GOES_HERE, order: ORDER_HERE}
method: 'GET',
success: function(html_data){
...
}
});
答案 2 :(得分:1)
使用Chrome或FF开发人员工具,在getMoreRecords
的第一行以及success
回调设置断点,然后单步执行JavaScript代码。
您也可以在JavaScript中添加debugger;
语句,而不是设置断点。
另外,请查看开发人员工具中的错误控制台和“网络”标签,并检查是否有任何可疑内容。
如果这没有帮助,至少应该为您提供更多信息来更新您的问题。