title: Iterating through objects to build a table with vertical headers in Rails
body: <p>I would like to build a table that has vertical headings and the NAME at the top of every column except the first which would have a blank first cell and then the table headings.</p>
  
  <p>My final table would be similar to this but instead of User1 and User2 it would be package1.name and package2.name.  And instead of date1 and date2 it would be Category and Full Price.</p>
  
  <p><a href="https://i.stack.imgur.com/H5BWb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H5BWb.jpg" alt="table example"></a></p>
  
  <p>However, I'm struggling to find the correct way to loop through.  This, of course, builds a horizontal table.</p>
  
  <pre><code>&lt;table class="table"&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;Category&lt;/th&gt;
        &lt;th&gt;Full price&lt;/th&gt;
        &lt;th&gt;Description&lt;/th&gt;
        &lt;th&gt;Expiration in months&lt;/th&gt;
        &lt;th colspan="3"&gt;&lt;/th&gt;
      &lt;/tr&gt;
    &lt;/thead&gt;
  
    &lt;tbody&gt;
      &lt;% @packages.each do |package| %&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;%= package.name %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= package.category %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= package.full_price %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= package.description %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= package.expiration_in_months %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= link_to 'Purchase', package %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= link_to 'Edit', edit_package_path(package) %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= link_to 'Destroy', package, method: :delete, data: { confirm: 'Are you sure?' } %&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;% end %&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>