Read more

Check whether a getter is an attribute or an association

Dominik Schöler
March 08, 2011Software engineer at makandra GmbH

Sometimes you might want to know if an attribute is an associated object or a simple string, integer etc. You can use the reflect_on_association Show archive.org snapshot method for that.

if Person.reflect_on_association(:address)
  Person.address.attributes # do something
else
  Person.address # do something else
end
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot
Posted by Dominik Schöler to makandra dev (2011-03-08 17:11)