class ActionView::Helpers::FormBuilder

def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")

#
# =>
check_box("accepted", { class: 'eula_check' }, "yes", "no")
# Let's say that @eula.accepted is "no":

#
# =>
check_box("gooddog", {}, "yes", "no")
# Let's say that @puppy.gooddog is "no":

#
# =>
check_box("validated")
# Let's say that @post.validated? is 1:

hashes instead of arrays.
In that case it is preferable to either use +check_box_tag+ or to use

get an extra ghost item with only that attribute, assigned to "0".
the elements of the array. For each item with a checked check box you
because parameter name repetition is precisely what Rails seeks to distinguish

<% end %>
...
<%= form.check_box :paid %>
<%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>

within an array-like parameter, as in
Unfortunately that workaround does not work when the check box goes

key in the query string, that works for ordinary forms.
form, and parameters extraction gets the last occurrence of any repeated
says key/value pairs have to be sent in the same order they appear in the
the check box is unchecked), or both fields. Since the HTML specification
This way, the client either sends only the hidden field (representing

attributes mimic an unchecked check box.
the very check box. The hidden field has the same name and its
To prevent this the helper generates an auxiliary hidden field before

wouldn't update the flag.

@invoice.update(params[:invoice])

any mass-assignment idiom like
invoice the user unchecks its check box, no +paid+ parameter is sent. So,
if an +Invoice+ model has a +paid+ flag, and in the form that edits a paid
thus web browsers do not send them. Unfortunately this introduces a gotcha:
The HTML specification says unchecked check boxes are not successful, and

==== Gotcha

while the default +unchecked_value+ is set to 0 which is convenient for boolean values.
Additional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1
It's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked.
assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object.
Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
  @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)
end