Ruby on rails 如果条件为false,则ruby on rails永远不起作用

Ruby on rails 如果条件为false,则ruby on rails永远不起作用,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,目前,我正在更新我的apias中if条件的一些值 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 th

目前,我正在更新我的
api
as中
if
条件的一些值

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\u detection.enabled=启用,如果启用

然后它一旦变成
TRUE
,它就再也不会回到
FALSE
,即使我把
enabled=FALSE
。为什么会这样?当我可以将enabled false设置为enabled false时,我希望它也为false运行,但它仅适用于
TRUE
,如果您只想为
运动检测分配
则永远不要返回false

。enabled=enabled
仅当为
启用的
提供了
值时

要做到这一点,你可以使用

motion_detection.enabled = enabled unless enabled.nil?

通过这种方式,您可以指定启用的
状态
,而不是其


这里有一把简单的红宝石小提琴来说明

对不起。。我没看到那部分…如果我没弄错你的问题。。当您将
设置为enabled=false
时,如果
正常工作,您希望获得
。。我的问题是,如果您将
enabled=false
放入,您认为
if
条件会起作用的原因是什么?enabled是一个值。我想知道如何解决这个问题,如果我把enabled设置为false,那么它应该用false更新值。如果你只想分配
motion\u detection.enabled=enabled
,只有在提供
for
enabled
时。。。要做到这一点,你可以使用
motion\u detection.enabled=如果启用则启用。是否存在?
。。通过这种方式,您可以指定启用的
状态
,而不是其值..它不起作用:)该值是真的,也是真的..最好的是上面的一个,除非,我的领导也喜欢,谢谢buddy@ijunaidfarooq锦鲤Dbari哲学mari hai推特pe:P glue wali:D@ijunaidfarooqbhai twitter使用nai karta main:PAcha ji?给我穆巴希尔·哈尼夫·萨布·康亨?阿拉玛·伊克巴尔·阿维·瓦勒D
motion_detection.enabled = enabled if !enabled.nil?