0
我想創建一個無盡的頁面。Rails 3.0如何創建無盡的頁面?
本教程後:http://railscasts.com/episodes/114-endless-page?view=comments
在我的控制,我有:
def index
@konkurrencer = Konkurrencer.find(:all).paginate(:page => params[:page], :per_page => 2)
respond_to do |format|
format.html
format.js { render :rjs => @konkurrencer }
end
end
在我看來,我有:
<% @konkurrencer.each do |kon| %>
<%= render :partial => 'konkurrencers/konkurrencer', :locals => { :kon => kon } %>
<% end %>
我index.js.rjs:
page.insert_html :bottom, :konkurrencer, :partial => 'konkurrencers/konkurrencer'
if @konkurrencer.total_pages > @konkurrencer.current_page
page.call 'checkScroll'
else
page[:loading].hide
end
在我的頭我此javascript:
<%= javascript_include_tag 'jquery', 'endless' %>
而且endless.js:
var currentPage = 1;
function checkScroll() {
if (nearBottomOfPage()) {
currentPage++;
new Ajax.Request('/konkurrencer.js?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);
有做什麼的沒有Ajax調用。應該將index.js.rjs移至index.js.erb?還是因爲我不包含默認的JavaScript?