Forum: Ruby on Rails Changing model attribute names

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.
Ryan G. (Guest)
on 2006-12-27 17:18

If I have a legacy db table named Users with a string named 'address1'
how can I map that to a User model with an attribute named
'street_address'?  I recognize how much easier it would be just to use
addess1 but some of the other columns have horrible names.

Thank you,
Ryan G.
on 2006-12-27 20:09
(Received via mailing list)

Have you tried creating accessors to make your User class appear to
have the street_address attribute?  E.G. within your User class...

def street_address

def street_address=(addr)
  write_attribute(:address1, addr)

You may also perhaps override the default accessors for address1 to
make them no-ops if you wanted to discourage such access.

Hope that helps!

Chris Eagan
This topic is locked and can not be replied to.