ActionView::Helpers::DateHelper
def select_date(date = Date.current, options = {}, html_options = {})

Description

Creates year, month and day <select> elements not bound to a model.

Arguments

Changing a value updates the ERB and HTML.

Accepts:
  • A date (such as a Date): its year, month and day: adds selected to the <option> elements with the same value.
  • A hash ({ year: 2026, month: 4 }): adds it only for the parts present in the hash. However, also passing discard_day or discard_month with a hash raises NoMethodError, because it tries to set the day to 1.
  • nil: adds selected to no <option>.
For the year, lists the 5 years before and after the given year (the current year if there is no year). For the day, lists 1 to 31 regardless of the month.
options= {}

Options for helpers without a model object

"payday"
Used as the prefix of name and id.

Options for the date <select> elements

[:day, :month, :year]
Orders the year, month and day <select> elements as given. Defaults to the order in the date.order translation. Year, month or day parts missing from the array become hidden <input> elements, as with discard_year and the like (without the month, the day also becomes a hidden one with a value of 1).
1980
The first year in the year <select>. Defaults to 5 years before the selected year.
1985
The last year in the year <select>. Defaults to 5 years after the selected year. If it is less than start_year, the years are listed newest first.
true uses numbers instead of names as the month <option> text.
true uses two-digit numbers as the month and day <option> text.
true uses both the number and the name as the month <option> text.
"%{number}: %{name}"
The format of the month <option> text. %{number} is replaced with the number and %{name} with the name.
->(year) { "Year #{year}" }
Calls the proc for each year and uses its return value as the text of that year's <option>.
->(day) { "Day #{day}" }
Calls the proc for each day and uses its return value as the text of that day's <option>.
" / "
Puts this string between the year, month and day <select> elements. The string is not escaped (character references such as &mdash; go into the HTML as is).
true replaces the day <select> with a hidden <input> whose value is 1.
true replaces the month <select> with a hidden <input>. The day <select> is also replaced, with a hidden <input> whose value is 1.
true replaces the year <select> with a hidden <input>.

Options for all <select> elements

true adds an <option> with an empty value at the top of every <select>.
Depending on the value:
  • true: adds an <option> with an empty value at the top of every <select>. Its text comes from translations such as datetime.prompts.year.
  • A string: adds an <option> with the string as its text at the top of every <select>.
  • A hash ({ year: "Year" }): adds one only to the <select> elements named by the keys (the year <select> for year), with the values as their text.
true adds disabled to every <select> and hidden <input>.
true adds a class to each <select>, such as class="year" for the year and class="hour" for the hour. A hash ({ year: "y" }) sets the class of each <select> named by a key to its value, and adds class="" to the other <select> elements. If the class html_option is also given, appends to it after a space (a hash or array class is turned into a string as is).
true replaces every <select> with a hidden <input>.
Rails handles options of the same name in almost the same way across all DateHelper helpers. Where one behaves differently, its description says so. locale uses that locale's translations for the month names, the prompt strings and the date.order order. Options that do not change the HTML, and ones this site considers rarely used, are not listed on this page.Options not listed here do not become HTML attributes.
html_options= {}
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 all helpers

{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.
Any other html_options become HTML attributes of all three <select> elements; those with a nil value are left out. id and name are also used as is for every <select>, instead of the generated values.

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