我正在定义以下模型方法:
def live
deb = start_date||= 100.years.ago # if the start date is nil, it's live
fin = end_date||=100.years.from_now # if the end date is nil, it's live
Date.today.between?(deb, fin)
end
如果填充了 start_date 和 end_date,则该方法返回正确的值(true 或 false),如果它们为 nil,则会引发错误“无法从 NilClass 迭代”