lib/rails_extensions.rb
def validate_each(record, attribute, value)
    unless record.public_send(:"#{attribute}_changed?") == options[:changeable]
      record.errors.add(attribute,
        "#{options[:changeable] ? 'must' : 'cannot'} be modified")
    end
  end
# Enforce/prevent attribute change
#
# Example: Make attribute immutable once saved
# validates :attribute, changeable: false, on: :update
#
# Example: Force attribute change on every save
# validates :attribute, changeable: true


Force attribute change on every save
validates :attribute, changeable: true
Force attribute change on every save validates : attribute changeable : true
def validate_each(record, attribute, value)
    unless record.public_send(:"#{attribute}_changed?") == options[:changeable]
      record.errors.add(attribute,
        "#{options[:changeable] ? 'must' : 'cannot'} be modified")
    end
  end
def validate_each ( record , attribute , value ) unless record . public_send ( :" #{ attribute } _changed? " ) == options [ :changeable ] record . errors . add ( attribute , "#{options[:changeable] ? 'must' : 'cannot'} be modified" ) end end
Enforce/prevent attribute change
Example: Make attribute immutable once saved
validates :attribute, changeable: false, on: :update
Enforce / prevent attribute change Example : Make attribute immutable once saved validates : attribute changeable : false on : : update
record
attribute
value