Is there a way to prevent an attribute from being changed from outside
the class instance? So that after a record is created, the attribute can
be read but cannot be changed from outside the class instance.
At first glance, "attr_readonly" seems to be the solution. However,
will "attr_readonly" also prevent the attribute from being changed even
from inside the class?
In other words, will the following method successfully change the values
of attribute_a and attribute_b in model A?
1.Class A < ActiveRecord::Base
2. attr_readonly :attribute_a, :attribute_b
3. def change_attributes(new_a, new_b)
4. self.attribute_a = new_a
5. self.attribute_b = new_b
I know I can redefine the write accessor if I want to customize the way
a single attribute is changed. However here I would like to change two
attributes in one transaction and prevent each attribute from being