public Method

FormTagHelper.radio_button_tag(name, value, checked = false, options = {})

Contents:

Creates a radio button; use groups of radio buttons named the same to allow users to select from a group of options.

Options

  • :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

radio_button_tag 'gender', 'male'
# => <input name="gender" type="radio" value="male" />

radio_button_tag 'receive_updates', 'no', true
# => <input checked="checked" name="receive_updates" type="radio" value="no" />

radio_button_tag 'time_slot', "3:00 p.m.", false, :disabled => true
# => <input name="time_slot" type="radio" disabled="disabled" value="3:00 p.m." />

radio_button_tag 'color', "green", true, :class => "color_input"
# => <input checked="checked" name="color" type="radio" value="green" />

Source Code

# File action_view/helpers/form_tag_helper.rb, line 308
def radio_button_tag(name, value, checked = false, options = {})
  pretty_tag_value = value.to_s.gsub(/\s/, "_").gsub(/(?!-)\W/, "").downcase
  pretty_name = name.to_s.gsub(/\[/, "_").gsub(/\]/, "")
  html_options = { "type" => "radio", "name" => name, "id" => "#{pretty_name}_#{pretty_tag_value}", "value" => value }.update(options.stringify_keys)
  html_options["checked"] = "checked" if checked
  tag :input, html_options
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.