instance method
validates!
Ruby on Rails 4.2.9
Since v3.2.22.5Signature
validates!(*attributes)
This method is used to define validations that cannot be corrected by end users and are considered exceptional. So each validator defined with bang or :strict option set to true will always raise ActiveModel::StrictValidationFailed instead of adding error when validation fails. See validates for more information about the validation itself.
class Person include ActiveModel::Validations attr_accessor :name validates! :name, presence: true end person = Person.new person.name = '' person.valid? # => ActiveModel::StrictValidationFailed: Name can't be blank
Parameters
-
attributesrest
Source
# File activemodel/lib/active_model/validations/validates.rb, line 145
def validates!(*attributes)
options = attributes.extract_options!
options[:strict] = true
validates(*(attributes << options))
end
Defined in activemodel/lib/active_model/validations/validates.rb line 145
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Validations::ClassMethods