Method: ActionView::Helpers::FormTagHelper#radio_button_tag
- Defined in:
- actionview/lib/action_view/helpers/form_tag_helper.rb
#radio_button_tag(name, value, *args) ⇒ Object
:call-seq:
(name, value, = {})
(name, value, checked, = {})
Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.
Options
-
:checked- If set to true, the radio button will be selected 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
'favorite_color', 'maroon'
# => <input id="favorite_color_maroon" name="favorite_color" type="radio" value="maroon" />
'receive_updates', 'no', true
# => <input checked="checked" id="receive_updates_no" name="receive_updates" type="radio" value="no" />
'time_slot', "3:00 p.m.", false, disabled: true
# => <input disabled="disabled" id="time_slot_3:00_p.m." name="time_slot" type="radio" value="3:00 p.m." />
'color', "green", true, class: "color_input"
# => <input checked="checked" class="color_input" id="color_green" name="color" type="radio" value="green" />
496 497 498 499 500 501 502 503 504 505 |
# File 'actionview/lib/action_view/helpers/form_tag_helper.rb', line 496 def (name, value, *args) if args.length >= 3 raise ArgumentError, "wrong number of arguments (given #{args.length + 2}, expected 2..4)" end = args. checked = args.empty? ? false : args.first = { "type" => "radio", "name" => name, "id" => "#{sanitize_to_id(name)}_#{sanitize_to_id(value)}", "value" => value }.update(.stringify_keys) ["checked"] = "checked" if checked tag :input, end |