From 436f16def4d7c842e543ceb6c1d94b97746f6d77 Mon Sep 17 00:00:00 2001 From: Luke Baker Date: Mon, 11 Jun 2012 12:00:43 -0400 Subject: [PATCH] gracefully handle nil values for min/max date --- app/controllers/questions_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index b7aec21..bb953dc 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -250,8 +250,8 @@ class QuestionsController < InheritedResources::Base data = Choice.count(:conditions => "choices.question_id = #{@question.id} AND choices.creator_id <> #{@question.creator_id}", :group => "date(choices.created_at)") # we want graphs to go from date of first vote -> date of last vote, so adding those two boundries here. - mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id}).to_date - maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id}).to_date + mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id}).try(:to_date) + maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id}).try(:to_date) data[mindate] = 0 if !data.include?(mindate) && !mindate.nil? data[maxdate] = 0 if !data.include?(maxdate) && !maxdate.nil? -- libgit2 0.21.2