DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Creating A Two Dimensional Table With Rails

11.04.2006
| 7135 views |
  • submit to reddit
        This code creates a two dimensional table out of data passed from the controller. The code is pretty basic, but there's not much documentation on it.

<table>
<% @instance.in_groups_of(5) do |row| %>
<tr> 
<% row.each do |data| %>
        # The nil check is required because Rails pads empty table cells with nil.
	<td><%= data.field unless data.nil? %></td>
<% end %>
</tr> 
<% end %>
</table>
    

Comments

Snippets Manager replied on Wed, 2006/08/09 - 8:32am

Small nitpick.. <%= data.field unless data.nil? %>