Jason Crystal
Jason Crystal

Reputation: 361

Having time_zone_select default to system timezone

How can I use the ActionView::Helpers::FormOptionsHelper method time_zone_select and have the selected value default to the current (system) timezone?

This works fine:

time_zone_select( "user", 
                  "time_zone",
                  nil,
                  :default => "Pacific Time (US & Canada)" )

How can I replace Pacific Time (US & Canada) with valid code for the current zone?

Upvotes: 2

Views: 1649

Answers (1)

infused
infused

Reputation: 24337

You can use Time.zone.name, so:

time_zone_select(:user, :time_zone, nil, default: Time.zone.name)

Upvotes: 4

Related Questions