Making a Real Calendar in Rails

For a while now, I have been looking at the various calendar helpers on Github. One thing stands out over all of them: they all suck.

bad_calendar

Why? well, they all implement the same basic concept – that is, they make a table containing rows for each week, and cells for each day, yielding in case the user wants to display anything other than a day number in the cell.

This is fine if all you want to do is display single-day events, but if you want to go to the next level and display multiple “all day” events it is practically impossible as the events are constrained in their table cell. Instead, another approach is needed.

good_calendar

The approach? Well, put simply the events are placed in a row below each set of day cells. Events which span more than 1 row are repeated, and a layout algorithm handles vertical placement.

Now rather than writing a whole post describing in agonising detail how to implement this approach, I thought i’d post a gist on github describing how to do it. Read it here. Any¬†improvements? Feel free to fork. Comments? feel free to post below!

Update: The great guy’s over at elevation have turned this code into a plugin. So if you don’t fancy implementing this all by yourself, just use the easy to install plugin. :)