跳至內容 跳至搜尋

Active Model StrictValidationFailed

當驗證無法由使用者修正,且被視為異常時引發。

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