跳至内容 跳至搜索

Active Model 严格验证失败

当验证无法由最终用户纠正且被视为异常时引发。

class Person
  include ActiveModel::Validations

  attr_accessor :name

  validates_presence_of :name, strict: true
end

person = Person.new
person.name = nil
person.valid?
# => ActiveModel::StrictValidationFailed: Name can't be blank