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.

The code:

<% @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?

High-Tech Creative Services http://new.techism.com/

Re: Combining dated events with calendar cells.

There is a very good railscast episode on calendars which may give you a few pointers.

Re: Combining dated events with calendar cells.

jamesc wrote:

There is a very good railscast episode on calendars which may give you a few pointers.

Do you have a link?  I saw one, but it was about which "handy plugins" you could use.  None of those address my needs.

High-Tech Creative Services http://new.techism.com/

Re: Combining dated events with calendar cells.

This is the one I'm refering to: http://railscasts.com/episodes/213-calendars

I did something similar to what you want to do with event_calendar. Take a look at the readme on GitHub and  there is a screenshot on Jeffs website http://dev.elevationblog.com/2009/7/23/ … ils-plugin

Re: Combining dated events with calendar cells.

jamesc wrote:

This is the one I'm refering to: http://railscasts.com/episodes/213-calendars

I did something similar to what you want to do with event_calendar. Take a look at the readme on GitHub and  there is a screenshot on Jeffs website http://dev.elevationblog.com/2009/7/23/ … ils-plugin

Yeah, like I said, a plugin won't do it.  I've already seen the screencast.  Doesn't really get into what I'm trying to do here...I'm writing my own custom calendar-oriented interface.

Got it working too, just concerned about how I'm merging my events in.

High-Tech Creative Services http://new.techism.com/

Re: Combining dated events with calendar cells.

I ended up using the plugin as a graphical display for the calender but also wrote my own events controller and views to accomplish inputting/ editing of events and displaying upcoming events in a sidebar.

Re: Combining dated events with calendar cells.

Well all I'm concerned with is how I merge in the events...I really need my own calendar views as custom designed since I'm doing quite a bit with them.  These are now complete and running great! Very modular, lean code.  Might make my own plugin when I'm done, who knows...

But I'm merging in more than events...I'm dealing with time sheet entries, reminders, mile-stones, etc...

Ideally, I'd like to pass my calendar some collections, and have it merge those into the calendar nicely...just not sure what the best logic for that would be.

High-Tech Creative Services http://new.techism.com/

Re: Combining dated events with calendar cells.

Rock Bottom Blueprint