I have the following and it bombs out when the method comes up "nil"? How can I default to no substtution in that case?
message.gsub("{FirstName}", contact.first_name).
gsub("{LastName}", contact.last_name).
gsub("{Title}", contact.title).
gsub("{Company}", contact.company_name.clear_company).
gsub("{Colleagues}", colleagues.to_sentence).
For example, I get an error when contact.title is nil. How can I prevent that in that instance?
I guess you can try appending .to_s
to each variable? ex. contact.first_name.to_s
. If it is nil, then it will become ""
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With