Returns a string of option tags for pretty much any time zone in the world. Supply a TimeZone name as selected to have it marked as the selected option tag. You can also supply an array of TimeZone objects as priority_zones, so that they will be listed above the rest of the (long) list. (You can use TimeZone.us_zones as a convenience for obtaining a list of the US time zones.)
The selected parameter must be either nil, or a string that names a TimeZone.
By default, model is the TimeZone constant (which can be obtained in ActiveRecord as a value object). The only requirement is that the model parameter be an object that responds to #all, and returns an array of objects that represent time zones.
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
Source Code
# File action_view/helpers/form_options_helper.rb, line 286 def time_zone_options_for_select(selected = nil, priority_zones = nil, model = TimeZone) zone_options = "" zones = model.all convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } } if priority_zones zone_options += options_for_select(convert_zones[priority_zones], selected) zone_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" zones = zones.reject { |z| priority_zones.include?( z ) } end zone_options += options_for_select(convert_zones[zones], selected) zone_options end
<code/>and<pre/>for code samples.