我有一個部分,我想刪除或不顯示數組中的前三篇文章,因爲它們在精選文章部分。我也希望部分使用will_paginate w /無限滾動來加載下一頁文章。我面臨的問題是,當使用@articles.drop(3).each do |a|
並下一頁加載時,該陣列會再次丟棄接下來的三篇文章。Rails will_paginate無限滾動與丟棄前3項的數組
解決這個問題的最佳方法是什麼?我最初的想法是一個數組內的數組,第一個數組放下第一個3,然後嵌套數組返回所有文章,但我不知道該怎麼做?在部分
陣列碼:
<% @articles.drop(3).each do |a| %>
<%= link_to a.source_url, :class => "flexRow" do %>
<%= a.source %>
<h3><%= a.title %></h3>
<% end %>
<% end %>
index.js.erb的
$('#article-index').append(' <%= j render("articles") %>');
<% if @articles .next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@articles, :previous_label => '', :next_label => '', :page_links => false) %>');
<% else %>
$('.pagination').remove();
<% end %>
Index.html.erb
<div id="article-index">
<%= render 'articles' %>
</div>
UPDATE 該解決方案似乎工作,但沒有按」你覺得優雅嗎?
<% (@articles.current_page == 1 ? @articles.drop(3) : @articles).each do |a| %>
感謝但這會導致一些funkiness與分頁,不是所有的文章出現。 –