【问题标题】:How to change mime type to text/html in rails 3?如何在 rails 3 中将 mime 类型更改为 text/html?
【发布时间】:2011-01-14 03:57:54
【问题描述】:

Rails 3 默认为 Content-Type: text/plain

我正在尝试发送 HTML 电子邮件。如何调整 MIME 类型?

【问题讨论】:

    标签: html ruby-on-rails mime-types


    【解决方案1】:

    只需在视图模板的扩展之前添加 .html 即可。

    app/views/user_mailer/welcome_email.html.erb
    

    【讨论】:

      【解决方案2】:

      我假设你在谈论 ActionMailer?像这样命名您的视图文件:

      app/views/mailer_name/method_name.text.plain.erb
      app/views/mailer_name/method_name.text.html.erb
      

      然后,在 text.plain 中,生成 HTML 电子邮件的纯文本版本。

      【讨论】:

      • 您在此处复制扩展名,只需 method_name.text.erb 即可...此外,您还需要在 Mailer 类的方法中使用 respond_to,这将导致它发送多包含文本和 html 组件的部分电子邮件。
      • 我不知道。谢谢!
      猜你喜欢
      • 2014-05-27
      • 2018-06-17
      • 2018-12-13
      • 2011-09-22
      • 2015-08-21
      • 2011-03-14
      • 2020-09-20
      • 2011-09-19
      • 1970-01-01
      相关资源
      最近更新 更多