ActionView::Helpers::DateHelper
def select_time(datetime = Time.current, options = {}, html_options = {})

Description

Creates hour and minute <select> elements not bound to a model.

Arguments

Changing a value updates the ERB and HTML.

Adds selected to the <option> elements whose value matches the hour and minute of this date and time. The year, month and day of this date and time become hidden <input> elements. With a hash that has no year, month or day ({ hour: 9, min: 30 }), or with nil, these hidden <input> elements have a value of 1. The hash key for the minute is min.
options= {}
true omits the hidden year, month and day <input> elements.

Options for helpers without a model object

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

Options for the time <select> elements

true adds a <select> for seconds ((6i)) after the minute <select>.
15
Fills the minute <select> with minutes in steps of this number. If the selected minute is not one of them, no <option> is selected.
9
The first hour in the hour <select>.
17
The last hour in the hour <select>.
true formats the hour <option> text as 12-hour time with AM and PM. The value stays in 24-hour time.
"h"
Puts this string between the hour and minute <select> elements, and also between the minute and seconds ones. The string is not escaped (character references such as &mdash; go into the HTML as is).
true adds a hidden <input> instead of the hour <select>.
true replaces the minute <select> with a hidden <input>. In datetime_select and select_datetime, the seconds from include_seconds: true also become 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 every <select>; 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