Changing model attribute names


#1

Hello,

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.


#2

Ryan-

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
read_attribute(:address1)
end

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

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