Ruby on rails check_box始终呈现已检查

时间:2015-03-19 22:35:01

标签: html ruby-on-rails ruby-on-rails-4

总是在dom中检查我的rails复选框。如何在页面加载时检查对象是否为真?

= f.check_box :split_funding, {class: "split_funding", :disabled => @survey.completed?, id: "split_funding_#{school.id}", "data-attribute" => "split_funding", "data-id" => school.id}

1 个答案:

答案 0 :(得分:0)

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}

我不确定你的意思是'如果对象是真的',所以我假设:split_funding将返回true / false。如果它是关系,您可以在末尾链接:present?以检查关系是否存在。