End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CGI::HtmlExtension#radio_button
radio_button(name = "", value = nil, checked = nil)
lib/cgi/html.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/cgi/html.rb, line 646
def radio_button(name = "", value = nil, checked = nil)
attributes = if name.kind_of?(String)
{ "TYPE" => "radio", "NAME" => name,
"VALUE" => value, "CHECKED" => checked }
else
name["TYPE"] = "radio"
name
end
input(attributes)
end
Generates a radio-button Input element.
name is the name of the input field. value is the value of the field if checked. checked specifies whether the field starts off checked.
Alternatively, the attributes can be specified as a hash.
Example
radio_button("name", "value") # <INPUT TYPE="radio" NAME="name" VALUE="value"> radio_button("name", "value", true) # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED> radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo") # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">