ActionView::Helpers::DateHelper
def select_hour(datetime, options = {}, html_options = {})

Description

Creates an hour <select> not bound to a model.

Arguments

Changing a value updates the ERB and HTML.

Adds selected to the <option> whose value matches the hour of this date and time (or the number itself, if a number is given). nil adds selected to no <option>.
options= {}

Options for helpers without a model object

"payday"
Used as the prefix of name and id.
"start"
The part of name inside the []. Also used as the part of id after the _.
true reduces name and id to just the prefix part.

Options for the time <select> elements

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.

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 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