module ActiveModel::Validations::HelperMethods
Public Instance Methods
validates_unchanged(*attr_names)
click to toggle source
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
# File lib/active_model/validations/unchanged_validator.rb, line 30 def validates_unchanged(*attr_names) validates_with UnchangedValidator, _merge_attributes(attr_names) end