The following code made sure that a time_zone
chose is within the time zones in ActiveSupport::TimeZone.us_zones
:
validates_inclusi
try adding .keys
?
validates :time_zone,
inclusion: {
in: ActiveSupport::TimeZone.zones_map.keys
}
If you want to keep using validates_inclusion_of
this works as well:
validates_inclusion_of :time_zone,
:in => ActiveSupport::TimeZone.zones_map(&:name).keys,
:message => "is not a valid time zone"
In Rails 5, ActiveSupport::TimeZone.zones_map
is a private method. Therefore, if you want your validation to work, I suggest the following syntax:
validates :time_zone, inclusion: { in: ActiveSupport::TimeZone.all.map(&:name) }