From a81333f115c877fc59601f4e0766df4bdce4a8d8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 21 Dec 2007 22:18:07 +0000 Subject: Add :default option to time_zone_select. Closes #10590. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8473 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/form_options_helper.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view/helpers/form_options_helper.rb') diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 0f1d2b02bf..67be4d81f0 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -131,6 +131,17 @@ module ActionView # to TimeZone. This may be used by users to specify a different time # zone model object. (See #time_zone_options_for_select for more # information.) + # Finally, this method supports a :default option, which selects + # a default TimeZone if the object's time zone is nil. + # + # Examples: + # time_zone_select( "user", "time_zone", nil, :include_blank => true) + # + # time_zone_select( "user", "time_zone", nil, :default => "Pacific Time (US & Canada)" ) + # + # time_zone_select( "user", 'time_zone', TimeZone.us_zones, :default => "Pacific Time (US & Canada)") + # + # time_zone_select( "user", "time_zone", TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {}) InstanceTag.new(object, method, self, nil, options.delete(:object)).to_time_zone_select_tag(priority_zones, options, html_options) end @@ -385,7 +396,7 @@ module ActionView value = value(object) content_tag("select", add_options( - time_zone_options_for_select(value, priority_zones, options[:model] || TimeZone), + time_zone_options_for_select(value || options[:default], priority_zones, options[:model] || TimeZone), options, value ), html_options ) -- cgit v1.2.3