ActionView::Helpers::FormTagHelper
def select_tag(name, option_tags = nil, options = {})

Description

Creates a <select> that is not tied to a model.

Arguments

Changing a value updates the ERB and HTML.

Used as the name and id attributes of the <select>. In the id, [, spaces and similar characters become _, and ] is removed.
The content of the <select>. A string returned by options_for_select or a similar helper is output as is, as <option> elements. A string that is not html_safe (such as "<option>…") is escaped, but not when :include_blank (true or a string) or :prompt is also given. nil leaves the content empty.
options= {}
true adds the multiple attribute and appends [] to the name. If the name already ends with [], it is not added again.
true adds an <option> with an empty value at the top. A string is used as its text.
"Select a plan"
Adds an <option> with an empty value at the top, with the given string as its text. true gives the literal text true.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <select>, and ones this site considers rarely used, are not listed here.

Shared by form helpers

"q"
Replaces the generated name with the given value. nil omits name.
nil
Replaces the generated id with the given value. nil omits id.

Shared by all helpers

true adds disabled="disabled"; false omits it. The same goes for every HTML attribute in Rails' list (BOOLEAN_ATTRIBUTES), such as readonly, required and autofocus: any value other than false or nil adds it as attr="attr".
{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
["section-user", "name"]
An array sets autocomplete to its elements joined with spaces.
Any other options become HTML attributes of the <select>; those with a nil value are left out.

ERB

Changes from the previous output: Added Removed Changed


          

HTML


          

Preview

Interacting with the preview updates the form submission.

Form submission

Form data

namevalue
Request body

Content-Type:


              

params