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

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

<% @instance.in_groups_of(5) do |row| %>
<% 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 %>
<% end %>


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

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