How to prevent a value from ever changing

problem: within the DB there is a special “empty” string, this string
must never be changed.

how to best enforce this rule?

Currently I have…


override the string_value setter,

to control empty string from ever being overwritten

ensure that the single empty string is never modified

def string_value=(sv)
if self[:string_value].blank? && !self.new_record?
raise “Empty String May Not Be Modified”
#errors.add(:string_value, “Empty String May Not Be Modified”)
else
self[:string_value] = sv
end
end


looking for better / more elegant ideas

thanks in advance

problem: within the DB there is a special “empty” string, this string
must never be changed.

how to best enforce this rule?

http://agilewebdevelopment.com/plugins/attrlocked

Or something similar to that maybe…

Currently I have…


override the string_value setter,

to control empty string from ever being overwritten

ensure that the single empty string is never modified

def string_value=(sv)
if self[:string_value].blank? && !self.new_record?
raise “Empty String May Not Be Modified”
#errors.add(:string_value, “Empty String May Not Be Modified”)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs