What I want is a “write once, then readonly” attribute in a subclass of
ActiveController::Base. With “write once” in this case I mean that it
must not be changed once the object has been stored to the database.
The simplified class looks as follows:
class User < ActiveRecord::Base
@login = new_login unless !new_record?
When I tested the method, I noticed that it behaved oddly:
An instance of User is created from the fixtures. Its login attribute is
set properly (checked it with Object::inspect). However, thatobj.login
returns nil. I thought it should be covered with the “attr_reader
:login” statement in the User class.
What am I missing here? Thanks in advance.