You should a method in the model. Then you can access this method
anywhere you have a User object. If you put it in the controller, you
will have to repeat yourself everytime you want User.status
In your model:
def status
"read" if....
etc.
end
In your controller
def show
@user=User.find(1)
#your show view can now read the status method
end
No… do not use after_initialize if you can avoid it. There are huge performance penalties, as in… it will be called any time you do a .new, or each time you create an instance. A finder that gets 50 records will call this code 50 times, and you can’t turn it off. If you look at the rails source, you’ll see comments basically warning you not to use after_initialize and after_find.
The best approach is to override the accessor as eggie5 suggested: