jjabrams
jjabrams

Reputation: 33

How to iterate after some data?

I have a product model with has_many images model

so on the first loop i just get the first 4 images

 <%  @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 %>

how to loop the rest of images after the first 4 images?

i've tried this: without sucess!

 <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>

Upvotes: 2

Views: 30

Answers (1)

Ilya
Ilya

Reputation: 13477

Use offset:

@product.images.offset(4).each { }

offset(4) means all records after first 4.

Upvotes: 1

Related Questions