【问题标题】:Rails - setting multiple layouts for a multipart email with mailer templatesRails - 使用邮件模板为多部分电子邮件设置多个布局
【发布时间】:2008-12-12 21:13:21
【问题描述】:

所以 Rails 2.2 添加了邮件布局,这很好,只是我不知道如何在我发送多部分电子邮件时使它们工作..它用相同的布局包装我的邮件内容文本/plain 版本和 text/html 版本。我想要的是仅将我的布局包裹在 text/html 版本周围,或者能够为每个版本提供单独的布局。

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

卡梅隆

【问题讨论】:

    标签: ruby-on-rails ruby actionmailer


    【解决方案1】:

    为了将来参考,上面在第二篇博文中修改的博文中的解决方案在下面给出了上述博文的所有功劳。 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
    

    【讨论】:

      猜你喜欢
      • 2021-04-13
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 2013-07-13
      • 2021-07-08
      • 2017-03-19
      • 2010-12-18
      • 2019-05-06
      相关资源
      最近更新 更多