Ruby on rails average per day

ruby-on-rails

Referencing this post:

ruby on rails average per day

I'm getting the average per day, which works fine. Until now that the month switched over…

I have this code

score = (7.days.ago.to_date.to_s(:db)..Date.today.tomorrow.to_s(:db)).map{|dt| [dt, ave_score[dt] || 0]}

Which works, but now that the month switches over, it comes back with dates that don't exist, like 2009-08-32 to 2009-08-99 and 2009-09-00. All in the array. How can I delete dates that don't actually exist.

Best Answer

Try waiting to make the call to to_s:

score = (7.days.ago.to_date..Date.today.tomorrow).map{ |dt| d = dt.to_s(:db); [d, ave_score[d] || 0] }