Learn how to use the very useful group_by method to group an array by anything you want! In this episode I group an array of tasks by month then sort it properly.
<% @task_months.sort.each do |month, tasks| %>
<h2><%= month.strftime('%B') %></h2>
<% for task in tasks %>
<div class="task">
<strong><%= task.name %></strong>
due on <%= task.due_at.to_date.to_s(:long) %>
</div>
<% end %>
<% end %>
<%@task_months.sort.each do |month, tasks| %><h2><%= month.strftime('%B') %></h2><%for task in tasks %><divclass="task"><strong><%= task.name %></strong>
due on <%= task.due_at.to_date.to_s(:long) %></div><%end%><%end%>