So what we know is that that name
, in particular, doesn't have an associated family
object. That is, name.family
is returning nil
, which doesn't respond to nome
, as indicated by the error. So, if what you're looking for is that this be handled gracefully... i.e. don't error and don't show anything in this case, you can do this:
<%= name.family.try(:nome) %>
The try
block will return nil
if name.family
is nil
and then the erb block will return an empty string, basically.
Otherwise, you'll need to figure out why one of the name
s in the loop doesn't have a family
and go from there.