select_datetime

select_datetime(datetime = Time.current, options = {}, html_options = {})
Instance Public methods

Returns a set of html select-tags (one for year, month, day, hour, minute, and second) pre-selected with the datetime. It's also 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 you do not supply a Symbol, it will be appended onto the :order passed in. You can also add :date_separator, :datetime_separator and :time_separator keys to the options to control visual display of the elements.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
my_date_time = Time.now + 4.days
 
# Generates a datetime select that defaults to the datetime in my_date_time (four days after today).
select_datetime(my_date_time)
 
# Generates a datetime select that defaults to today (no specified datetime)
select_datetime()
 
# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with the fields ordered year, month, day rather than month, day, year.
select_datetime(my_date_time, order: [:year, :month, :day])
 
# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with a '/' between each date field.
select_datetime(my_date_time, date_separator: '/')
 
# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# with a date fields separated by '/', time fields separated by '' and the date and time fields
# separated by a comma (',').
select_datetime(my_date_time, date_separator: '/', time_separator: '', datetime_separator: ',')
 
# Generates a datetime select that discards the type of the field and defaults to the datetime in
# my_date_time (four days after today)
select_datetime(my_date_time, discard_type: true)
 
# Generate a datetime field with hours in the AM/PM format
select_datetime(my_date_time, ampm: true)
 
# Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
# prefixed with 'payday' rather than 'date'
select_datetime(my_date_time, prefix: 'payday')
 
# Generates a datetime select with a custom prompt. Use <tt>prompt: true</tt> for generic prompts.
select_datetime(my_date_time, prompt: {day: 'Choose day', month: 'Choose month', year: 'Choose year'})
select_datetime(my_date_time, prompt: {hour: true}) # generic prompt for hours
select_datetime(my_date_time, prompt: true) # generic prompts for all
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.