我需要从数组中的特定点开始遍历数组直到它的最后。
例如:
<% @posts[6.."To the very end of array"].each do |post| %>
<%= render partial: 'posts/post', locals: {post: post} %>
<% end %>
这是我正在尝试完成的更完整的示例。
<% @posts.each do |post| %>
<% if post == @posts.first && !params[:page] %>
<div class="hidden-phone hidden-tablet">
<%= render partial: 'posts/main_post', locals: {post: post} %>
</div>
<div class="visible-phone visible-tablet">
<%= render partial: 'posts/post', locals: {post: post} %>
</div>
<%= render partial: 'posts/add_post' %>
<% end %>
<% end %>
<% @posts[1..5].each do |post| %>
<%= render partial: 'posts/post', locals: {post: post} %>
<% end %>
<%= render partial: 'posts/add2_post' %>
<% @posts[6..11].each do |post| %>
<%= render partial: 'posts/post', locals: {post: post} %>
<% end %>
<%= render partial: 'posts/add3_post' %>
<% @posts[12.."To the very end of array"]each do |post| %>
<%= render partial: 'posts/post', locals: {post: post} %>
<% end %>
有没有更有效的方法来实现这一点?
谢谢你的帮助。