0

my rails checkbox is always checked in the 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}

1 Answer 1

0

Pass it the checked attribute like so:

= 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. If it's a relation, you can chain :present? on the end to check for presence of the relation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.