Commit 436f16def4d7c842e543ceb6c1d94b97746f6d77

Authored by Luke Baker
1 parent ca2a2340

gracefully handle nil values for min/max date

thanks to Mark Lee for pointing this bug out.  min/max date
will be nil if there are no votes for a question.
Showing 1 changed file with 2 additions and 2 deletions   Show diff stats
app/controllers/questions_controller.rb
... ... @@ -250,8 +250,8 @@ class QuestionsController < InheritedResources::Base
250 250 data = Choice.count(:conditions => "choices.question_id = #{@question.id} AND choices.creator_id <> #{@question.creator_id}",
251 251 :group => "date(choices.created_at)")
252 252 # we want graphs to go from date of first vote -> date of last vote, so adding those two boundries here.
253   - mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id}).to_date
254   - maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id}).to_date
  253 + mindate = Vote.minimum('date(created_at)', :conditions => {:question_id => @question.id}).try(:to_date)
  254 + maxdate = Vote.maximum('date(created_at)', :conditions => {:question_id => @question.id}).try(:to_date)
255 255  
256 256 data[mindate] = 0 if !data.include?(mindate) && !mindate.nil?
257 257 data[maxdate] = 0 if !data.include?(maxdate) && !maxdate.nil?
... ...