instance method select_date

Ruby on Rails 7.0.10

Since v2.2.3

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

select_date(date = Date.current, options = {}, html_options = {})

Returns a set of HTML select-tags (one for year, month, and day) pre-selected with the date. It’s possible to explicitly set the order of the tags using the :order option with an array of symbols :year, :month and :day in the desired order. If the array passed to the :order option does not contain all the three symbols, all tags will be hidden.

If anything is passed in the html_options hash it will be applied to every select tag in the set.

my_date = Time.now + 6.days

# Generates a date select that defaults to the date in my_date (six days after today).
select_date(my_date)

# Generates a date select that defaults to today (no specified date).
select_date()

# Generates a date select that defaults to the date in my_date (six days after today)
# with the fields ordered year, month, day rather than month, day, year.
select_date(my_date, order: [:year, :month, :day])

# Generates a date select that discards the type of the field and defaults to the date in
# my_date (six days after today).
select_date(my_date, discard_type: true)

# Generates a date select that defaults to the date in my_date,
# which has fields separated by '/'.
select_date(my_date, date_separator: '/')

# Generates a date select that defaults to the datetime in my_date (six days after today)
# prefixed with 'payday' rather than 'date'.
select_date(my_date, prefix: 'payday')

# Generates a date select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
select_date(my_date, prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' })
select_date(my_date, prompt: { hour: true }) # generic prompt for hours
select_date(my_date, prompt: true) # generic prompts for all

Parameters

date opt = Date.current
options opt = {}
html_options opt = {}
Source
# File actionview/lib/action_view/helpers/date_helper.rb, line 450
      def select_date(date = Date.current, options = {}, html_options = {})
        DateTimeSelector.new(date, options, html_options).select_date
      end

Defined in actionview/lib/action_view/helpers/date_helper.rb line 450 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::DateHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close