Can't calculate first harvest if there are no harvests

This commit is contained in:
Brenda Wallace
2017-11-05 16:20:51 +13:00
parent b1684b0156
commit 9d11bcc039

View File

@@ -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