I would like to have a number of dynamic attributes for the user model, for example, phone, address, zipcode, etc., but I would not want to add them to the database. Therefore, I created a separate table called UserDetailsfor the key-value pairs and belongs_to :User.
Is there a way to somehow do something dynamic, like this one user.phone = "888 888 8888", which essentially will call a function that does:
UserDetail.create(:user => user, :key => "phone", :val => "888 888 8888")
and then have the appropriate recipient:
def phone
UserDetail.find_by_user_id_and_key(user,key).val
end
All this, but for a number of attributes provided as a phone, zip code, address, etc., without the arbitrary addition of a ton of getters and setters?
source
share