What is the best way to ensure that a model exists before doing string interpolation? I have a variable user
, and I need to see what the user
's major is. A table in between named user_attributes
has the user's info.
#{user.user_attribute.major.name}
The user may not have specified a major yet, in which case they wouldn't have a major model instance yet. So when I try and get the name of the major, I would get an "undefined method on nil class type" error. Any advice on how to safely do this?