Rails: form_for checkbox set to true or false whether the box is checked/unchecked

Rails will do this for you when your form is acting on an object, just leave all the extra stuff off the tag like so:

<div class="field">
    <%= f.label "Get Email" %> <br />
    <%= f.check_box :send_email %> <br />
</div>

And it should all start working as you expect. The checkboxes will be ticked if the attribute is true, and vice versa the checked state when you submit the form will affect the attribute. Rest of your code is fine.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)