ruby - create table rows of 4 in rails -


i have these checkboxes, i'm trying create rows of 4 checkboxes. @ moment creates 1 row.

<table>   <%= f.collection_check_boxes :expertise_ids, expertise.all, :id, :name |b| %>       <td>         <label style="margin-left:5px; margin-right:15px;" class="checkbox-inline">          <%= b.check_box %>          <%= b.label %>         </label>       </td>   <% end %> </table>                  

iv have tried this:

<table>   <%= f.collection_check_boxes :expertise_ids, expertise.all, :id, :name |b| %>     <% tablerows = 0 %>       <td>         <label style="margin-left:5px; margin-right:15px;" class="checkbox-inline">          <%= b.check_box %>          <%= b.label %>          <% tablerows += 1 %>          <% break if tablerows == 3 %>         </label>       </td>   <% end %> </table> 

im trying iterate on , every time counts 4 in trying generate new row, i'm not sure how complete this.

you can use in_groups_of:

<table>   <% expertise.all.in_groups_of(4, false) |expertise_group| %>     <tr><!-- new row each group of 4 -->       <%= f.collection_check_boxes :expertise_ids, expertise_group, :id, :name |b| %>          <td><!-- each checkbox column on own -->            <label style="margin-left:5px; margin-right:15px;" class="checkbox-inline">              <%= b.check_box %>              <%= b.label %>            </label>         </td>       <% end %>     </tr>   <% end %> </table> 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -