Method: ActionView::Helpers::FormTagHelper#check_box_tag
- Defined in:
- actionview/lib/action_view/helpers/form_tag_helper.rb
#check_box_tag ⇒ Object
:call-seq:
checkbox_tag(name, = {})
checkbox_tag(name, value, = {})
checkbox_tag(name, value, checked, = {})
Creates a check box form input tag.
Options
-
:value
- The value of the input. Defaults to"1"
. -
:checked
- If set to true, the checkbox will be checked by default. -
:disabled
- If set to true, the user will not be able to use this input. -
Any other key creates standard HTML options for the tag.
Examples
checkbox_tag 'accept'
# => <input id="accept" name="accept" type="checkbox" value="1" />
checkbox_tag 'rock', 'rock music'
# => <input id="rock" name="rock" type="checkbox" value="rock music" />
checkbox_tag 'receive_email', 'yes', true
# => <input checked="checked" id="receive_email" name="receive_email" type="checkbox" value="yes" />
checkbox_tag 'tos', 'yes', false, class: 'accept_tos'
# => <input class="accept_tos" id="tos" name="tos" type="checkbox" value="yes" />
checkbox_tag 'eula', 'accepted', false, disabled: true
# => <input disabled="disabled" id="eula" name="eula" type="checkbox" value="accepted" />
466 467 468 469 470 471 472 473 474 475 |
# File 'actionview/lib/action_view/helpers/form_tag_helper.rb', line 466 def checkbox_tag(name, *args) if args.length >= 4 raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..4)" end = args. value, checked = args.empty? ? ["1", false] : [*args, false] = { "type" => "checkbox", "name" => name, "id" => sanitize_to_id(name), "value" => value }.update(.stringify_keys) ["checked"] = "checked" if checked tag :input, end |