Class: ActiveModel::Validations::UnchangeableValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::UnchangeableValidator
- Defined in:
- lib/validates_unchangeable/active_model.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, _value) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/validates_unchangeable/active_model.rb', line 8 def validate_each(record, attribute, _value) if !record.public_send("#{attribute}_changed?") || (record.try(:new_record?) && !record.public_send(attribute).nil?) return end record.errors.add(attribute, :unchangeable) end |