From 9af30f7916698c2f6d187d2de86cd8972775727b Mon Sep 17 00:00:00 2001 From: Gleb Pereyaslavsky Date: Thu, 14 Apr 2011 23:20:54 +0400 Subject: [PATCH] Remove events with nil dates out of the list. This also fixes an error when one of these fields is nil --- lib/has_calendar.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/has_calendar.rb b/lib/has_calendar.rb index a39157d..9ed1434 100644 --- a/lib/has_calendar.rb +++ b/lib/has_calendar.rb @@ -53,7 +53,12 @@ def calendar(options={}, &block) private def group_events(events, field) - events.group_by { |event| event.send(field).to_date.jd } if events + if events + field = event.send(field) + grouped_events = events.group_by { |event| field.to_date.jd if field} + grouped_events.delete(nil) + grouped_events + end end def days_for_calendar