ActionView::Helpers::FormOptionsHelper

time_zone_select

API docs (Rails 8.1.4.1) ↗
def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})

Description

Creates a time zone <select> bound to a model attribute.

Arguments

Changing a value updates the ERB and HTML.

object:user
method:time_zone
= nil
Time zones to list first, followed by a disabled divider <option> (-------------) and then the remaining time zones. Takes an array of ActiveSupport::TimeZone objects or a regular expression. A regular expression picks the time zones whose name, or whose identifier such as Asia/Tokyo, matches it (/Tokyo/ also picks Osaka and Sapporo, which use Asia/Tokyo).
options= {}
"Tokyo"
Adds selected to the <option> whose value matches the object's value. When the object has no value, adds it to the <option> for this time zone instead.
true adds an <option> with an empty value at the top. A string sets its text. Passing false raises ArgumentError when the :required option in html_options is true, unless :multiple is true or :size is not 1.
true adds an <option> with an empty value at the top, but only when the object's value is empty. Its text is the helpers.select.prompt translation, or Please select if there is none. A string sets its text.
The options not listed here are used as follows. Others are ignored.
  • :model: replaces ActiveSupport::TimeZone with the given class and lists what its all returns.
  • :include_hidden: the same as in select.
  • :required, :multiple and :size: moved to html_options and become HTML attributes of the <select>.
  • :selected and :disabled: have no effect on the time zone <option> elements. With :selected, the prompt is not shown; with disabled: "", the prompt <option> gets disabled.
html_options= {}
true adds the required attribute, plus an <option> with an empty value at the top even without the :include_blank option. The blank <option> is left out when a truthy :prompt option is given, or when the :multiple option in html_options is true or :size is not 1.
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 html_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