gpt4 book ai didi

ruby-on-rails - Rails - 使用邮件程序模板为多部分电子邮件设置多个布局

转载 作者:数据小太阳 更新时间:2023-10-29 08:56:03 24 4
gpt4 key购买 nike

所以 Rails 2.2 添加了邮件程序布局,这很棒,除了当我发送多部分电子邮件时我无法弄清楚如何让它们工作..它用相同的布局包装我的邮件内容/plain 版本和 text/html 版本。我想要的是仅围绕 text/html 版本包装我的布局,或者能够为每个版本提供单独的布局。

有人遇到过这个吗?我没有在其他地方看到任何提及,

卡梅伦

最佳答案

为了将来引用,上面博客文章中的解决方案在第二篇博客文章中进行了修改,下面将所有内容都归功于上述博客文章。 Solution blog post

将此代码添加到您的 environment.rb 文件以阻止邮件程序将布局应用于纯文本电子邮件。它还有一个检查,可以阻止它与异常通知插件发生冲突。

# Do not use the mailer layout template for plain text emails
module ActionMailer
class Base
private
def candidate_for_layout?(options)
(!options[:file] || !options[:file].respond_to?(:content_type) ||
options[:file].content_type != 'text/plain') &&
!@template.send(:_exempt_from_layout?, default_template_name)
end
end
end

关于ruby-on-rails - Rails - 使用邮件程序模板为多部分电子邮件设置多个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/364162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com