Rails и начинающий программирование здесь.
Я пытаюсь реализовать бесконечную страницу из Railscast 114, но она не загружается.Консоль Firebug выдает ошибку:
document.observe не является функцией - document.observe ('dom :loaded', checkScroll);
Пытались найтипричины, по которым не загружен Prototype, а HTML показывает, что он загружен.Также попытался добавить часть формата в контроллер, предложенный в другом ответе, но он, похоже, не работает.
Код немного отличается от кода Райана, поскольку я выполняю рендеринг из канала.
_feed.html.erb
<% if @feed_items.any? %>
<%= javascript_include_tag :defaults, 'endless_page', 'prototype' %>
<div id="promotions" summary="Status feed">
<%= render :partial => 'shared/feed_item', :collection => @feed_items %>
</table>
<% end %>
pages_controller.rb
class PagesController < ApplicationController
def home
@title = "Home"
if signed_in?
@promotion = Promotion.new
@feed_items = current_user.feed.paginate(:page => params[:page])
respond_to do |format|
format.js
format.html
end
end
end
endless_page.js
var currentPage = 1;
function checkScroll() {
if (nearBottomOfPage()) {
currentPage++;
new Ajax.Request('/?page=' + currentPage, {asynchronous:true, evalScripts:true, method:'GET'});
} else {
setTimeout("checkScroll()", 250);
}
}
function nearBottomOfPage() {
return scrollDistanceFromBottom() < 150;
}
function scrollDistanceFromBottom(argument) {
return pageHeight() - (window.pageYOffset + self.innerHeight);
}
function pageHeight() {
return Math.max(document.body.scrollHeight, document.body.offsetHeight);
}
document.observe('dom:loaded', checkScroll);
feed.js.rjs
page.insert_html :bottom, :promotions, :partial => @feed_items
if @feed_items.total_pages > @feed_items.current_page
page.call 'checkScroll'
else
page[:loading].hide
end