我已經完成使用will_paginate寶石分頁現在我想要無限滾動使用這個寶石,我已經遵循railcast和這SO鏈接和寫入所有關於此的代碼。問題是數據很好,但當我向下滾動時,它會在頁面上重複多次。我不知道它爲什麼這樣做。任何幫助將是可觀的。無盡的滾動給滾動到下一頁的模板錯誤
我的控制器代碼:
def locations
merchants = Merchant.where("role = ?", 'Merchant')
@merchants_data = merchants.paginate(:page => params[:page], :per_page => 20)
respond_to do |format|
format.html
format.js
end
end
_location.html.erb:
<table>
<tr>
<th>
Name
</th>
</tr>
<% @merchants_data.each do |x| %>
<tr>
<td>
<%= x.name %>
</td>
</tr>
<% end %>
</table>
<%= will_paginate @merchants_data %>
home.js.coffee:
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').text('Fetching more locations...')
$.getScript(url)
$(window).scroll()
location.js。 erb:
$('#locations').append('<%= j render partial: "locations", collection:@merchants_data %>');
<% if @merchants_data.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@merchants_data) %>');
<% else %>
$('.pagination').remove();
<% end %>
errormessage是什麼? –
@huanson它給ActionView :: MissingTemplate錯誤。 –
對不起,但它很愚蠢地說exception_class!你已經說過它的缺失模板。顯然我們(或者我)要求它的投擲路徑,所以他尋找哪個模板並且找不到。 ;) –