From 9d11bcc0399fc4bf0ff772980bb63b481ef8bc2c Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sun, 5 Nov 2017 16:20:51 +1300 Subject: [PATCH] Can't calculate first harvest if there are no harvests --- app/models/planting.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/planting.rb b/app/models/planting.rb index 8d41e9bd2..a33b82b31 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -114,6 +114,7 @@ class Planting < ActiveRecord::Base end def update_harvest_days + return unless harvests.size.positive? # how long ago was this planted first_harvest = (harvests.first.harvested_at - planted_at).to_i last_harvest = finished? ? (harvests.last.harvested_at - planted_at).to_i : nil