instance method time_select

Ruby on Rails 2.2.3

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

time_select(object_name, method, options = {}, html_options = {})

Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified time-based attribute (identified by method) on an object assigned to the template (identified by object). You can include the seconds with :include_seconds.

This method will also generate 3 input hidden tags, for the actual year, month and day unless the option :ignore_date is set to true.

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

Examples

# Creates a time select tag that, when POSTed, will be stored in the post variable in the sunrise attribute
time_select("post", "sunrise")

# Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted
# attribute
time_select("order", "submitted")

# Creates a time select tag that, when POSTed, will be stored in the mail variable in the sent_at attribute
time_select("mail", "sent_at")

# Creates a time select tag with a seconds field that, when POSTed, will be stored in the post variables in
# the sunrise attribute.
time_select("post", "start_time", :include_seconds => true)

# Creates a time select tag with a seconds field that, when POSTed, will be stored in the entry variables in
# the submission_time attribute.
time_select("entry", "submission_time", :include_seconds => true)

# You can set the :minute_step to 15 which will give you: 00, 15, 30 and 45.
time_select 'game', 'game_time', {:minute_step => 15}

The selects are prepared for multi-parameter assignment to an Active Record object.

Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month choices are valid.

Parameters

object_name req
method req
options opt = {}
html_options opt = {}
Source
# File actionpack/lib/action_view/helpers/date_helper.rb, line 217
      def time_select(object_name, method, options = {}, html_options = {})
        InstanceTag.new(object_name, method, self, options.delete(:object)).to_time_select_tag(options, html_options)
      end

Defined in actionpack/lib/action_view/helpers/date_helper.rb line 217 · 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