Forum: Ruby on Rails Overriding column accessors?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Woei S. (Guest)
on 2006-01-14 03:02

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
This topic is locked and can not be replied to.