method

time_select

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.

3Notes

Styling question

hayafirst · Oct 24, 20081 thank

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

Changing time/date separators

skalee · Jan 6, 20131 thank

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

Set time zone in before filter

autonomous · Jul 30, 2008

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

end