Thought this might of some use to someone out there.
attr_immutable is simple plugin for Rails 0.14.3+ which will cause
flagged as immutable to be just that: immutable. The attributes
be rendered frozen on read, and throw an
assignment only after the record has been persisted (save/
create) or loaded
Comments and suggestions welcome.
Download and extract the following into your vendor/plugins
class User < ActiveRecord
attr_immutable :username # Make username immutable after
me = User.new
me.username = ‘testuser’ => ‘testuser’
me.password = ‘testpassword’ => ‘testpassword’
me.save => true
me.username.frozen? => true
me[:username].frozen? => true
me.attributes[‘username’].frozen? => true
me.username = ‘anotherusername’ =>
me[:username] = ‘anotherusername’ =>
This plugin was developed using Rails 0.14.3. It may work on previous
versions. Use at your own risk.
John M. email@example.com