Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add <div> to "each block" each 2 results with rails 3

I have a each block something like:

<% for f in @following %>
 <div class="span6">
  <%= f.name %>
 </div>
<% end %>

html result:

<div class="span6"> John</div>
<div class="span6"> kevin</div>
<div class="span6"> Peter</div>
<div class="span6"> Andrew</div>
.
.
.

I want add a <div class="row"></div> each 2 results something like:

<div class="row">
 <div class="span6"> John</div>
 <div class="span6"> kevin</div>
</div>
<div class="row">
 <div class="span6"> Peter</div>
 <div class="span6"> Andrew</div>
</div>

I want show 2 results per/row. How can I do it?

like image 297
hyperrjas Avatar asked Jan 16 '23 06:01

hyperrjas


1 Answers

Checkout each_slice

<% @following.each_slice(2) do |followers| %>
  <div class="row">
    <% followers.each do |f| %>
      <div class="span6">
        <%= f.name %>
      </div>
    <% end %>
  </div>
<% end %>
like image 160
Kyle Avatar answered Jan 29 '23 13:01

Kyle