# In the context of Rails app (mailers) | |
# Somewhere in email helper | |
def from_address_by(person_name) | |
return nil unless person_name | |
address = Mail::Address.new AppConfig.email.from # ex: "john@example.com" | |
address.display_name = person_name # ex: "John Doe" | |
address.format # returns "John Doe <john@example.com>" | |
end | |
# being used in the mailer as: | |
def invitation_email(invitation) | |
from_name = invitation.invited_by.try(:name) | |
mail from: from_address_by(from_name) | |
end | |
# Reminds my about https://www.destroyallsoftware.com/screencasts/catalog/how-and-why-to-avoid-nil |
This comment has been minimized.
This comment has been minimized.
Yea, thos are some of the options. The invitation can legitimately be without Where "no name" state should be checked? Who is responsible for that? Should Too many questions, that |
This comment has been minimized.
This comment has been minimized.
By "raise an exception" I don't mean raising it manually (which may be an option). Just do |
This comment has been minimized.
This comment has been minimized.
If you can send w/o name, you should have "from-address" anyway. In this case, Should you not send an invitation w/o name, you'd need a |
This comment has been minimized.
You want to raise an exception in
invitation_email
to be caught by smthng like Airbrake. Then, if an invitation can legitimately be w/oname
, you need to check this and not even call that mailer.