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
,只有在提供值forenabled
时。。。要做到这一点,你可以使用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?