ActionView::Helpers::FormOptionsHelper
def weekday_select(object, method, options = {}, html_options = {}, &block)

Description

Creates a <select> of the days of the week, bound to a model attribute.

Arguments

Changing a value updates the ERB and HTML.

object:user
method:day
options= {}
"金曜日"
Adds selected to the <option> whose value matches the given value, but only when the object has no value. With index_as_value: true, pass the day's number (the page's example, Friday, selects nothing).
true uses the day number instead of its name as the value of each <option> (Sunday is 0, Monday is 1). By default, the value is also the translated day name (date.day_names), so it changes with the page's language: Monday from Rails' built-in English locale, or the name from the app's locale files in other languages (月曜日 on this site's Japanese pages).
The key under date. whose translation is used as the text of each <option>: :day_names (Monday) or :abbr_day_names (Mon). Unless index_as_value is true, the value uses the same name.
The day to start the list from. Defaults to Date.beginning_of_week (:monday in this app).
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 (or the :selected option, if given) 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.
  • :include_hidden: the same as in select.
  • :required, :multiple and :size: moved to html_options and become HTML attributes of the <select>.
  • :disabled: has no effect on the day <option> elements. disabled: "" gives the prompt <option> the disabled attribute.
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