我有一个带有 has_many 图像模型的产品模型
所以在第一个循环中我只得到前 4 张图片
<% @product.images.first(4).each do |i| %>
<li>
<a href="<%= i.photo.url.to_s %>">
<%= image_tag(i.photo.url(:small).to_s, :class => 'thumbnail circle', :'data-zoom-href' => i.photo.url(:big).to_s) %>
</a>
</li>
<% end %>
如何在前 4 张图片之后循环播放其余图片?
我试过了:没有成功!
<ul>
<% @product.images.last.each do |i| %>
<li>
<a href="<%= i.photo.url.to_s %>">
<%= image_tag(i.photo.url(:small).to_s, :class => 'thumbnail circle', :'data-zoom-href' => i.photo.url(:big).to_s) %>
</a>
</li>
<% end %>
</ul>
最佳答案
使用偏移
:
@product.images.offset(4).each { }
offset(4)
表示前 4 之后的所有记录。
关于ruby-on-rails - 如何在一些数据之后进行迭代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36826257/