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

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. Examples:

  time_select("post", "sunrise")
  time_select("post", "start_time", :include_seconds => true)

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

Show source
Register or log in to add new notes.
October 24, 2008
1 thank

Styling question

How do we style the select boxes and “:” somehow within this method?

Follwup: it seems in Rails 2.1, FormBuilder#time_select didn’t pass html_options to this method. and it’s fixed i

July 30, 2008 - (v2.1.0)
1 thank

2.1 sets UTC time by default

Rails 2.1 sets hour select to UTC time value, not local server time by default. So if you’re not in UTC time zone don’t forget to specify timezone in your config/environment.rb: config.time_zone = 'Vilnius'

January 6, 2013
1 thank

Changing time/date separators

@hayafirst — it is possible to remove that “:” or change it to something else. Just pass `:time_separator` option. Inspect ActionView::Helpers::DateTimeSelector#separator method for more.

July 30, 2008
0 thanks

Set time zone in before filter

To set your time zone you could create a before_filter in your application.rb controller

class ApplicationController < ActionController::Base

 before_filter :set_timezone

 def set_timezone
   Time.zone = 'GMT'