rails/rails — pull request #16974 by masone (2014-09-19 09:44:59+00:00)
Title: mark mail as called after instead of before processing the mail

#16163 introduced raising an exception when mail attachments get added after the method `mail` was called since it seems to produce problems with the email body. The change checks if `@_mail_was_called` is true which gets set on one of the first lines in `mail`. I suggest that we move it to the end of the method.

The background why I request this change is that we add inline attachments as the mail view gets rendered by overwriting the `image_tag` view helper.

```
def image_tag(path, options={})
if URI.parse(path).relative?
controller.attachments.inline[path] ||= File.read("#{Rails.root}/app/assets/images/#{path}")
path = attachments[path].url
end
super(path, options)
end
```

This way all the images we use get attached transparently. Very convenient.

The above change raises because `@_mail_was_called` the time the view is rendered. The big question is, if my change would reintroduce the problem or support both requirements. Maybe @joakimk or @senny can help with that?