目前我正在if
中将api
条件的某些值更新为
motion_detection.frequency = frequency if frequency
motion_detection.minPosition = minPosition if minPosition
motion_detection.step = step if step
motion_detection.min = min if min
motion_detection.threshold = threshold if threshold
motion_detection.enabled = enabled
motion_detection.alert_email = alert_email if alert_email
motion_detection.alert_interval_min = alert_interval_min if alert_interval_min
motion_detection.sensitivity = sensitivity if sensitivity
motion_detection.x1 = x1 if x1
motion_detection.x2 = x2 if x2
motion_detection.y1 = y1 if y1
motion_detection.y2 = y2 if y2
motion_detection.schedule = JSON.parse(inputs["schedule"]) if schedule
motion_detection.save
motion_detection
如果我放motion_detection.enabled = enabled if enabled
那么一旦它TRUE
,即使我放FALSE
,它也永远不会回到enabled = false
。为什么会这样?我想让它运行为假,因为我可能会启用false但它只适用于TRUE
然后永远不会回到假
答案 0 :(得分:0)
如果您只想在motion_detection.enabled = enabled
提供value
时才指定enabled
...
要做到这一点,你可以使用..
motion_detection.enabled = enabled unless enabled.nil?
或
motion_detection.enabled = enabled if !enabled.nil?
这样您就可以presence
分配enabled
而不是value
..
这是一个简单的红宝石小提琴来说明rubyfiddle