HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/default/doc/actionview-6.1.4.1/ri/ActionView/Helpers/FormHelper/check_box-i.ri
U:RDoc::AnyMethod[iI"check_box:ETI".ActionView::Helpers::FormHelper#check_box;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[
I"oReturns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object ;TI"|assigned to the template (identified by +object+). This object must be an instance object (@object) and not a local object. ;TI"uIt's intended that +method+ returns an integer and if that integer is above zero, then the checkbox is checked. ;TI"sAdditional options on the input tag can be passed as a hash with +options+. The +checked_value+ defaults to 1 ;TI"\while the default +unchecked_value+ is set to 0 which is convenient for boolean values.;To:RDoc::Markup::BlankLineS:RDoc::Markup::Heading:
leveli	:	textI"Gotcha;T@o;
;	[
I"OThe HTML specification says unchecked check boxes are not successful, and ;TI"Qthus web browsers do not send them. Unfortunately this introduces a gotcha: ;TI"Pif an +Invoice+ model has a +paid+ flag, and in the form that edits a paid ;TI"Oinvoice the user unchecks its check box, no +paid+ parameter is sent. So, ;TI"#any mass-assignment idiom like;T@o:RDoc::Markup::Verbatim;	[I"'@invoice.update(params[:invoice])
;T:@format0o;
;	[I"wouldn't update the flag.;T@o;
;	[I"KTo prevent this the helper generates an auxiliary hidden field before ;TI"Dthe very check box. The hidden field has the same name and its ;TI"-attributes mimic an unchecked check box.;T@o;
;	[
I"KThis way, the client either sends only the hidden field (representing ;TI"Othe check box is unchecked), or both fields. Since the HTML specification ;TI"Osays key/value pairs have to be sent in the same order they appear in the ;TI"Nform, and parameters extraction gets the last occurrence of any repeated ;TI"<key in the query string, that works for ordinary forms.;T@o;
;	[I"IUnfortunately that workaround does not work when the check box goes ;TI"*within an array-like parameter, as in;T@o;;	[	I"V<%= fields_for "project[invoice_attributes][]", invoice, index: nil do |form| %>
;TI"#  <%= form.check_box :paid %>
;TI"  ...
;TI"<% end %>
;T;0o;
;	[I"Tbecause parameter name repetition is precisely what Rails seeks to distinguish ;TI"Kthe elements of the array. For each item with a checked check box you ;TI"Gget an extra ghost item with only that attribute, assigned to "0".;T@o;
;	[I"KIn that case it is preferable to either use +check_box_tag+ or to use ;TI"hashes instead of arrays.;T@o;;	[I"-# Let's say that @post.validated? is 1:
;TI"$check_box("post", "validated")
;TI"C# => <input name="post[validated]" type="hidden" value="0" />
;TI"k#    <input checked="checked" type="checkbox" id="post_validated" name="post[validated]" value="1" />
;TI"
;TI".# Let's say that @puppy.gooddog is "no":
;TI"4check_box("puppy", "gooddog", {}, "yes", "no")
;TI"C# => <input name="puppy[gooddog]" type="hidden" value="no" />
;TI"Y#    <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
;TI"
;TI"Icheck_box("eula", "accepted", { class: 'eula_check' }, "yes", "no")
;TI"C# => <input name="eula[accepted]" type="hidden" value="no" />
;TI"k#    <input type="checkbox" class="eula_check" id="eula_accepted" name="eula[accepted]" value="yes" />;T;0:
@fileI"+lib/action_view/helpers/form_helper.rb;T:0@omit_headings_from_table_of_contents_below000[I"T(object_name, method, options = {}, checked_value = "1", unchecked_value = "0");T@PFI"FormHelper;TcRDoc::NormalModule00