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.
9ced25040ef51a7d985591aa452d9e18?d=identicon&s=25 Ryan Glover (prion)
on 2006-12-27 16: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 Glover
A7ddb1186c8e0e02860a30382772818f?d=identicon&s=25 (Guest)
on 2006-12-27 19: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.