How do I dynamiclly get an attribute value for an activerecord object?
for example I have a variable named attr_name. I want to do something like this
attr_name
send is the method you're looking for.
If doing this using send
send
address = person.send("function_name" + "attr_name")
Either use person.attributes[attr_name] or person.read_attribute(att_name), or even shorter then this is person[attr_name].
person.attributes[attr_name]
person.read_attribute(att_name)
person[attr_name]