【发布时间】:2017-07-24 15:05:16
【问题描述】:
我想删除或不显示数组中的前三篇文章的部分内容,因为它们位于精选文章部分。我还希望部分使用 will_paginate w/无限滚动来加载下一页文章。我面临的问题是,当使用@articles.drop(3).each do |a| 并加载下一页时,该数组再次删除了接下来的三篇文章。
解决此问题的最佳方法是什么?我最初的想法是数组中的数组,其中第一个数组删除前 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>
更新 这个解决方案似乎有效,但感觉不优雅?
<% (@articles.current_page == 1 ? @articles.drop(3) : @articles).each do |a| %>
【问题讨论】:
标签: javascript ruby-on-rails arrays ruby-on-rails-4 will-paginate