# 查询字段是否为验证字段,如果是验证字段返回 true def presence?(poi, field) presence_fields = poi.constantize.validators.map do |v| v.attributes if v.is_a? ActiveRecord::Validations::PresenceValidator end # 去 nil 并 二维转一维 if presence_fields.compact.flatten.include?(field) return true else return false end end end