【发布时间】:2016-01-04 03:24:11
【问题描述】:
我正在尝试在我的用户配置文件中为 time_zones 创建一个选择下拉列表,但我需要匹配列表和索引,因为我没有使用文本,我使用整数来将区域存储在我的数据库中.我这样做是为了在 rails admin 中将其显示为下拉菜单,而不是文本输入。
用户:
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
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4