title: How to use group_by date with datetime element to display on calendar by day?
body: <p>I'm using a datetime element on my model but for some reason I can't get it to show up in my calendar. I'm using code in the controller and view to do this, the CSS is irrelevant I think so I wont include that. I'm also using a hash to do it.</p>
  
  <p>Events Controller:</p>
  
  <pre><code>  def calendarpage
      @events = Event.all
      @events_by_date = @events.group_by(&amp;:edate)
      @date = params[:date] ? Date.parse(params[:date]) : Date.today
    end
  </code></pre>
  
  <p>CalendarPageView:</p>
  
  <pre><code>&lt;h1&gt;My Calendar&lt;/h1&gt;
  &lt;div id="events"&gt;
  &lt;h2 id="month"&gt;
      &lt;%= link_to "&lt;", date: @date.prev_month %&gt;
      &lt;%= @date.strftime("%B %Y") %&gt;
      &lt;%= link_to "&gt;", date: @date.next_month %&gt;
  &lt;/h2&gt;
  &lt;%= calendar @date do |date| %&gt;
    &lt;%= date.day %&gt;
    &lt;% if @events_by_date[date] %&gt;&lt;!-- is this even populated?? --&gt;
      &lt;ul&gt;
          &lt;% @events_by_date[date].each do |event| %&gt;
              &lt;li&gt;&lt;%= link_to event.title, event%&gt;&lt;/li&gt; &lt;!-- THIS IS WHAT DOESN'T SHOW --&gt;
          &lt;% end %&gt;
      &lt;/ul&gt;   
    &lt;% end %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Here's the relevant database entries:
  table: events</p>
  
  <pre><code>id  title   ... edate
  "1" "Test"  ... "2014-10-06 20:38:00.000000"
  "2" "t2"    ... "2014-10-07 20:40:00.000000"
  </code></pre>
  
  <p>This might also be useful, though I don't think so: 
  Calendar Helper.rb</p>
  
  <pre><code>module CalendarHelper
      def calendar(date = Date.today, &amp;block)
          Calendar.new(self, date, block).table
      end
  
      class Calendar &lt; Struct.new(:view, :date, :callback)
          HEADER = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
          START_DAY = :sunday
  
          delegate :content_tag, to: :view
  
          def table 
              content_tag :table, class: "calendar" do 
                  header + week_rows              
              end
          end
  
          def header
              content_tag :tr do
                  HEADER.map { |day| content_tag :th, day }.join.html_safe
              end
          end
  
          def week_rows
              weeks.map do |week|
                  content_tag :tr do
                      week.map { |day| day_cell(day) }.join.html_safe
                  end
              end.join.html_safe
          end
  
          def day_cell(day)
              content_tag :td, view.capture(day, &amp;callback), class: day_classes(day)
          end
  
          def day_classes(day)
              classes = []
              classes &lt;&lt; "today" if day == Date.today
              classes &lt;&lt; "notmonth" if day.month != date.month
              classes.empty? ? nil : classes.join(" ")
          end
  
          def weeks
              first = date.beginning_of_month.beginning_of_week(START_DAY)
              last = date.end_of_month.end_of_week(START_DAY)
              (first..last).to_a.in_groups_of(7)
          end
      end
  end
  </code></pre>
  
  <p>the calendar displays just fine, and I know that the controller code does get called. But none of the events actually get displayed at all. the 6th and the 7th don't get displayed.</p>
  
  <p>Now, Here's what I'm thinking. I followed a tutorial to make this and I'm thinking that in the tutorial the edate element is a :date element not a :datetime element like I have it, would that make a difference? if so how do I correct for difference in variable type (the extra time info)? if this is the problem do I have to change the Group_by line in the event controller?</p>
  
  <p>One other observation I have is that I appended this code onto the bottom of the view page:</p>
  
  <pre><code>&lt;% @events_by_date["7"].each do |event| %&gt;
      &lt;li&gt;&lt;%= link_to event.title, event%&gt;&lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>and I got an error:</p>
  
  <pre><code>undefined method `each' for nil:NilClass
  </code></pre>
  
  <p>This may be because I don't understand how Hashtables work, but something is telling me the @events_by_date isn't being populated in the controller :(</p>
  
  <p>what do I do?</p>