Forum: Ruby on Rails Overriding column accessors?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fcdafe495dccc04d27f6dbbcdf54aecc?d=identicon&s=25 Woei Shyang (generik)
on 2006-01-14 02:02
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?
This topic is locked and can not be replied to.