Reputation: 351
I am using time_zone_select to list all the time zones in my select box. by default it displays list as follows :
(GMT-11:00) American Samoa
(GMT-11:00) International Date Line West
(GMT-11:00) Midway Island
.
.
.
etc.
But, I wanted it to display as follows :
American Samoa (GMT-11:00)
Alaska (GMT-09:00)
That is I want city name first and sorted by name
I managed to sort it , but coud not change the sequence
= f.time_zone_select( "user", "time_zone", ActiveSupport::TimeZone.all.sort_by{|e| e.name}, model: ActiveSupport::TimeZone)
Upvotes: 1
Views: 440
Reputation: 323
have a look at here
this should work for you
<%= f.select("user", "time_zone", ActiveSupport::TimeZone.all.sort_by(&:name).map{|m|["#{m.name} (GMT#{m.formatted_offset})"]}, model: ActiveSupport::TimeZone) %>
# this comment is to avoid stack-overflow horizontal slider overlap for single line codes. ;p
Upvotes: 0
Reputation: 6749
You can do it using select
instead of time_zone_select
= f.select( "user", "time_zone", ActiveSupport::TimeZone.all.sort_by(&:name).map{|e| "#{e.name}(GMT#{e.formatted_offset})"})
Upvotes: 2