title: How to group events objects under a single shared date with group_by
body: <p>I am attempting to list events that share the same date under a single date table header.</p>
  
  <p>I came across <a href="https://stackoverflow.com/questions/11720513/listing-objects-under-the-date-they-were-created">this Stack Overflow question</a> which I think has guided me in the right direction, but not entirely solved my problem.</p>
  
  <p>I'm using the following code in my view:</p>
  
  <pre><code>&lt;% @events = @organization.events.group_by{|x| x.when} %&gt;
  &lt;% @events.each do |listing| %&gt;
      &lt;p&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;th&gt;
                      &lt;%= listing.when %&gt;
                  &lt;/th&gt;
              &lt;/tr&gt;
                  &lt;% listing.each do |list| %&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;%= list.name %&gt; given by
                              &lt;% list.vips.each do |v| %&gt;
                                  &lt;%= v.name %&gt;
                              &lt;% end %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;% end %&gt;   
          &lt;/table&gt;
      &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>The error I get is "undefined method `when' for #Array:0x007fc781f9b000"</p>
  
  <p>When I use the console, @events prints out the following:</p>
  
  <pre><code>{Mon, 24 Aug 2015 00:00:00 UTC +00:00=&gt;[#&lt;Event id: 7, when: "2015-08-24 00:00:00", organization_id: 4, created_at: "2015-08-24 05:42:59", updated_at: "2015-08-24 05:42:59", name: "Initial Captain's Brief", vip_id: 1&gt;, #&lt;Event id: 8, when: "2015-08-24 00:00:00", organization_id: 4, created_at: "2015-08-24 05:43:08", updated_at: "2015-08-24 05:43:08", name: "Ryan's Event", vip_id: 2&gt;]}
  </code></pre>
  
  <p>What I really don't understand is, when I replace</p>
  
  <pre><code>&lt;%= listing.when %&gt;
  </code></pre>
  
  <p>With</p>
  
  <pre><code>&lt;%= listing %&gt;
  </code></pre>
  
  <p>I get a new error saying "undefined method `name' for Mon, 24 Aug 2015 00:00:00 UTC +00:00:Time"</p>
  
  <p><strong>Overall</strong> </p>
  
  <ul>
  <li>Is the object being returned by @organizations.events.group_by{|x| x.when} a hash with a <em>key</em> of Mon, Aug 24 2015 and multiple <em>values</em> consisting of the events matching that <em>key</em>?</li>
  <li>Is there a way to correctly code my example such that it has a single date as a table header and then event listings in the rows beneath it without errors?</li>
  </ul>