Rails field_for confusion -


note pretty new rails, please don't hate me much.

i want have 2 different table rows of entries object. understand, code this.

<%= form_for(@object) |f| %> <table>   <tr>     <th> col 1 </th>     <th> col 2 </th>     <th> col 3 </th>     <th> col 4 </th>     <th> col 5 </th>     <th> col 6 </th>     <th> col 7 </th>   </tr>   <tr>     <!-- entries 1-7 here --!>   </tr>   <tr>     <!-- entries 8-14 here --!>   </tr> </table> <% end %> 

but can tell, using <% fields_for(@object.entries) |entry| %> forces me go through of them @ once whe want first half second half. know have 14 entries per object (1 day 2 weeks), , i'd see them in 2 rows (1 row per week). ideas how go doing this?

you can use #each_slice enumerable chunk them iterate. like:

<%= form_for(@object) |f| %> <table>   <tr>     <th> col 1 </th>     <th> col 2 </th>     <th> col 3 </th>     <th> col 4 </th>     <th> col 5 </th>     <th> col 6 </th>     <th> col 7 </th>   </tr>   <% @object.entries.each_slice(7) |arr| %>     <% arr.each |obj| %>       <tr>         <!-- entries n-n+7 here -->       </tr>     <% end %>   <% end %> </table> <% end %> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -