Overriding column accessors?


#1

Hi,

Is it possible to override the default accessors that are created by
Rails? For instance I had this User object which has the column headings
“password” and “salt” in its SQL table.

I did manage to override the setter accessor for password by using def
password=(new_password), but when I tried doing the same for the reader
by using a def password method (to return a blank string always),
nothing happens.

The “edit” view in the scaffold still managed to pull my hashed password
out and display it in the textbox all the same!

Ideally what I’m trying to achieve is to make the salt and password
values completely unreadable from outside the class (except through
perhaps read_attribute and write_attribute). Is it possible to do just
that?