Topic: Combining dated events with calendar cells.
I'm pretty sure that I picked a kinda resource-eating way of handling this.
The problem: I want to add a div for each billable item that corresponds to a date within a calendar day's td.
The current solution: I look up all billable for that day as the cell is rendered.
The good: 30 mysql calls on a month view leans on mysql to handle the processing. No fancy code needed in models or controller to support the calendar functionality.
The bad: 30 mysql calls? I might have only two billable items...doing 30 requests to display two items is stupid. Queries in views = yuck.
<% @billables = current_user.billables.where(:date => day...(day + 1.day)) %> <td class="date_cell <%=classes%>" id="<%=day%>"> <span class="day_number"><%= day.strftime('%d') %></span> <% @billables.each do |billable| %> <div class="billable"></div> <% end %> </td>
What I imagine: Is there a nice light-weight way to get a collection of say, all the billable for the month, that can be somehow "searched" or meshed in when the calendar is being drawn without making a processor intensive pain?
Maybe I somehow turn the billables collection into a keyed hash?
Given that billables for a month could be 1000 items, or only 2, depending on user:
Which is better practice / leaner? Doing 30 queries or crunching over a larger collection on rails' dime?