Rails passing an object to a mailer

I have a theoretical question about the mail program in Rails. I heard a couple of times that transferring resources directly to the mail program is not considered good practice. And it's better to just pass the id to load the object. For example, it is in this question that the accepted answer says: Rails: Absolutely deadlock with delayed_job. Do not get arguments anywhere

But if so, what are the reasons for this ban? I can not consider the related issue as an exhaustive explanation. Thank you for your suggestions.

+4
source share
1 answer

The reason is simple: it is more than a 0% chance that your object will be changed in the meantime, when you ordered sending mail and executing the real code of the mail program. Imagine that the object you are using will be deleted in the process, but since you did not load your object at run time, it will try to use an instance of the object that no longer exists. I think now you understand the problem.

+3
source

Source: https://habr.com/ru/post/1438458/


All Articles