Module: ActiveModel::Validations::HelperMethods
- Defined in:
- lib/active_model/validations/unchanged_validator.rb
Instance Method Summary collapse
-
#validates_unchanged(*attr_names) ⇒ Object
Validates that the specified attributes are unchanged (unless the record is new).
Instance Method Details
#validates_unchanged(*attr_names) ⇒ Object
Validates that the specified attributes are unchanged (unless the record is new). Happens by default on save.
class Person < ActiveRecord::Base
validates_unchanged :first_name
end
The first_name attribute must be in the object and it must not have changed.
Configuration options:
-
:message
- A custom error message (default is: “must not change”).
There is also a list of default options supported by every validator: :if
, :unless
, :on
, :allow_nil
, :allow_blank
, and :strict
. See ActiveModel::Validation#validates
for more information
30 31 32 |
# File 'lib/active_model/validations/unchanged_validator.rb', line 30 def validates_unchanged(*attr_names) validates_with UnchangedValidator, _merge_attributes(attr_names) end |