Using Walters solution has worked. contact.company.try(:company_name) So my understanding of this now is that because some of the contact records have no company defined (a nil object or NilClass). By using .try it responds nil if no company is found.
So does that mean that if I have a field that uses a foreign key but is not required I should use eg. try(*a, &b)? Or is there another solution? Thank you. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.