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

On Sep 9, 2:11 am, “Jeffrey L. Taylor” [email protected] wrote:

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 ?

Fred

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

On Thu, Sep 9, 2010 at 3:52 AM, Frederick C.
<[email protected]

and still be able to use the new version of rails

Quoting Frederick C. [email protected]:

On Sep 9, 2:11 am, “Jeffrey L. Taylor” [email protected] wrote:

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

On Sep 10, 1:30 am, “Jeffrey L. Taylor” [email protected] wrote:

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