[英]Ruby on rails check_box always rendering checked
my rails checkbox is always checked in the dom. 我的rails复选框始终在dom中选中。 How can I make it so when the page loads it's checked if the object is true or not?
如何在页面加载时检查对象是否为真?
= f.check_box :split_funding, {class: "split_funding", :disabled => @survey.completed?, id: "split_funding_#{school.id}", "data-attribute" => "split_funding", "data-id" => school.id}
Pass it the checked
attribute like so: 向其传递
checked
属性,如下所示:
= f.check_box :split_funding, {checked: @survey.split_funding, class: "split_funding", :disabled => @survey.completed?, id: "split_funding_#{school.id}", "data-attribute" => "split_funding", "data-id" => school.id}
I'm not sure what you mean by 'if the object is true', so I am assuming that :split_funding
will return true/false. 我不确定“如果对象为true”是什么意思,所以我假设
:split_funding
将返回true / false。 If it's a relation, you can chain :present?
如果是关系,您可以链接
:present?
on the end to check for presence of the relation. 最后检查该关系是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.