0
我試圖爲我的用戶配置文件中的time_zones創建選擇下拉列表,但我需要列表和索引進行匹配,因爲我沒有使用文本,我正在使用整數用於將區域存儲在我的數據庫中。我這樣做,所以我可以顯示它作爲下拉欄管理員而不是文本輸入。時區下拉列表中選擇值是索引
用戶:
validates_inclusion_of :time_zone, in: ActiveSupport::TimeZone.us_zones.map { |z| z.name },
message: "is not a valid time zone",
allow_blank: true
# This allows me to display the time_zone as a dropdown in rails admin instead of a text box
TIMEZONES = ActiveSupport::TimeZone.us_zones.map { |z| z.name }
def time_zone_enum
TIMEZONES.each_with_index.to_a
end
查看:這裏所描述
<%= f.collection_select :time_zone, ActiveSupport::TimeZone.us_zones.map { |z| z.name }, value, name %>
# I don't know how to get the value to be an index of the map operation and to display the name