以下代码确保time_zone选择在ActiveSupport :: TimeZone.us_zones的时区内:
validates_inclusion_of :time_zone,in: ActiveSupport::TimeZone.zones_map(&:name)
在Rails 4.0中工作得很好.刚升级到Rails 4.1,我在索引页面上收到此错误(所以只需查看模型):
An object with the method #include? or a proc,lambda or symbol is
required,and must be supplied as the :in (or :within) option of the
configuration hash
我猜测,ActiveSupport :: TimeZone.zones_map(&:name)不再是in属性的有效值?
解决方法
尝试添加.keys?
validates :time_zone,inclusion: { in: ActiveSupport::TimeZone.zones_map.keys }