On Sep 10, 1:30 am, "Jeffrey L. Taylor" <r...@abluz.dyndns.org> wrote: > Quoting Frederick Cheung <frederick.che...@gmail.com>: > > > > > On Sep 9, 2:11 am, "Jeffrey L. Taylor" <r...@abluz.dyndns.org> 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. >
You could overwrite the read accessor to call freeze! for you. Fred > Thanks, > Jeffrey -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.