End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
CGI::HtmlExtension#checkbox
checkbox(name = "", value = nil, checked = nil)
lib/cgi/html.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.2.0/lib/cgi/html.rb, line 180
def checkbox(name = "", value = nil, checked = nil)
attributes = if name.kind_of?(String)
{ "TYPE" => "checkbox", "NAME" => name,
"VALUE" => value, "CHECKED" => checked }
else
name["TYPE"] = "checkbox"
name
end
input(attributes)
end
Generate a Checkbox Input element as a string.
The attributes of the element can be specified as three arguments, name, value, and checked. checked is a boolean value; if true, the CHECKED attribute will be included in the element.
Alternatively, the attributes can be specified as a hash.
Example
checkbox("name") # = checkbox("NAME" => "name") checkbox("name", "value") # = checkbox("NAME" => "name", "VALUE" => "value") checkbox("name", "value", true) # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)