2016-09-12 75 views
0

我正在使用time_zone_select列出我的選擇框中的所有時區。默認情況下它顯示列表如下:自定義time_zone_select導軌4.0

(GMT-11:00) American Samoa 
(GMT-11:00) International Date Line West 
(GMT-11:00) Midway Island 
. 
. 
. 
etc. 

不過,我希望它顯示如下:

American Samoa (GMT-11:00) 
Alaska (GMT-09:00) 

這是我第一次希望城市名稱和名稱排序

我設法排序它,但coud不改變序列

= f.time_zone_select("user", "time_zone", ActiveSupport::TimeZone.all.sort_by{|e| e.name}, model: ActiveSupport::TimeZone) 

回答

0

你可以使用select我的time_zone_select

= f.select("user", "time_zone", ActiveSupport::TimeZone.all.sort_by(&:name).map{|e| "#{e.name}(GMT#{e.formatted_offset})"}) 
+0

太謝謝你了:) –

0

nstead看看here

這應該爲你工作

<%= 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 
+0

謝謝@坐的:) –