您好我正在通过制作Pinterest克隆在线课程学习Ruby。
尝试无限滚动工作,并在控制台中收到错误。
这不在课程中,所以我一直在尝试关注这个帖子
Endless page with will_paginate not working with partial
我做了OP在线程中所做的一切,但出于某种原因,我滚动页面时出现了一些错误,当滚动下来后应该加载下一个项目时,还会出现500(内部服务器错误)页。
我的进程项目在这里:http://clawomr-pinteresting.herokuapp.com/ 如果向下滚动,您将看到错误。
我认为值得关注的代码是:
pins.js
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
if $('.pagination').length # Thats for the Endless Scrolling
$(window).scroll ->
url = $('.pagination .next_page a').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
# What to do at the bottom of the page
$('.pagination').text("Fetching more Pins...")
$.getScript(url)
$(window).scroll()
pins_controller.rb
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
def index
@pins = Pin.order("created_at DESC").page(params[:page]).per_page(7)
respond_to do |format|
format.html
format.js
end
end
...
index.js.erb的的
$boxes = $('<%= j render(@pins) %>')
$('#pins').append( $boxes ).imagesLoaded( function(){
$('#pins').masonry( 'reload');
});
<% if @clips.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@pins) %>');
<% else %>
$('.pagination').remove();
<% end %>
Github来源 https://github.com/cablecharlz/pinteresting
这是服务器控制台上显示的错误
Processing by PinsController#index as JS
Parameters: {"page"=>"2", "_"=>"1389830140527"}
Pin Load (0.5ms) SELECT "pins".* FROM "pins" ORDER BY created_at DESC LIMIT 7 OFFSET 7
Rendered pins/index.js.erb (4.9ms)
Completed 500 Internal Server Error in 11ms
ActionView::Template::Error (Missing partial pins/pin with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/Charles/Desktop/pinteresting/app/views"
* "/Users/Charles/.rvm/gems/ruby-2.0.0-p353/gems/devise-3.2.2/app/views"
):
1: $boxes = $('<%= j render(@pins) %>')
2:
3: $('#pins').append( $boxes ).imagesLoaded( function(){
4: $('#pins').masonry( 'reload');
app/views/pins/index.js.erb:1:in `_ app_views_pins_index_js_erb__4093603127232543635_2186204660'
app/controllers/pins_controller.rb:14:in `index'
滚动时的错误
ce.event.dispatch application-3e70b62b8e586fea0e41235d8bbc0f00.js:2
v.handle application-3e70b62b8e586fea0e41235d8bbc0f00.js:2
ce.event.trigger application-3e70b62b8e586fea0e41235d8bbc0f00.js:2
(anonymous function) application-3e70b62b8e586fea0e41235d8bbc0f00.js:2
ce.extend.each application-3e70b62b8e586fea0e41235d8bbc0f00.js:1
ce.fn.ce.each application-3e70b62b8e586fea0e41235d8bbc0f00.js:1
ce.fn.extend.trigger application-3e70b62b8e586fea0e41235d8bbc0f00.js:2
ce.fn.(anonymous function) application-3e70b62b8e586fea0e41235d8bbc0f00.js:3
(anonymous function)
答案 0 :(得分:0)
我对砌体的了解并不多,但我会尽力帮助。首先,我建议用will_paginate观看Ryan Bates'screencast无休止的滚动。您可以看到Github源here。
正如我所看到的,问题是你没有在索引视图中渲染你的Pin-partial。你应该这样做:
索引视图
<div id="pins" class="transitions-enabled">
<%= render @pins%>
</div>
_Pin.html.erb partial
<div class="someclass">
<% @pins.each do |pin| %>
#pin code
</div>
重要的是,您的javascript与html中的类和ID名称匹配。