Freeze an attribute?

Is it possible to to freeze a single attribute of an ActiveRecord (Rails 2.3.5). Hopefully in a way that isn't deprecated in 2.3.8 or 3.0.

TIA,   Jeffrey

attr_readonly ?

Fred

@frederick i think he want to freeze a feature of and old rails version so he doesnt need to migrate his app

and still be able to use the new version of rails

Quoting Frederick Cheung <frederick.cheung@gmail.com>:

> Is it possible to to freeze a single attribute of an ActiveRecord (Rails > 2.3.5). Hopefully in a way that isn't deprecated in 2.3.8 or 3.0. > attr_readonly ?

Not quite what I wanted, but interesting none the less. I wanted an attribute that could not be modified in memory. From the documentation, this allows it to be modified, but won't write the modified value to the DB.

I think a way to do this is create the value on object instantiation, freeze it, and then assign it to the attribute. It's a calculated value in an ActiveRecord that has associated objects. I want to make sure, one of the associated objects doesn't modify the value. No write accessor just prevents changing the attribute to refer to a different object. It does not prevent modifying the assigned object.

Thanks,   Jeffrey

Quoting Frederick Cheung <frederick.che...@gmail.com>:

> > Is it possible to to freeze a single attribute of an ActiveRecord (Rails > > 2.3.5). Hopefully in a way that isn't deprecated in 2.3.8 or 3.0.

> attr_readonly ?

Not quite what I wanted, but interesting none the less. I wanted an attribute that could not be modified in memory. From the documentation, this allows it to be modified, but won't write the modified value to the DB.

I think a way to do this is create the value on object instantiation, freeze it, and then assign it to the attribute. It's a calculated value in an ActiveRecord that has associated objects. I want to make sure, one of the associated objects doesn't modify the value. No write accessor just prevents changing the attribute to refer to a different object. It does not prevent modifying the assigned object.

You could overwrite the read accessor to call freeze! for you.

Fred