Rails:邮件和文本部分的UTF-8编码问题 [英] Rails: UTF-8 encoding issue with mailer and text partials

查看:140
本文介绍了Rails:邮件和文本部分的UTF-8编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Rails应用程序,并且我的文本邮件程序面临一个问题:我找不到如何使特殊字符(é,è,à,...)被正确编码。

它可以很好地与html邮件程序,因为我可以设置< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/> 但是这不可能与文本邮件程序。



文本邮件程序中的问题示例(my_mailer.text.erb)

  D&#233; monstration#Démonstration

我的邮件摘录

 邮件来自:< from> ,
to:< to>,
subject:< subject>
body:< body>

我还尝试添加 charset:'utf-8'属性到邮件方法没有成功。
如何解决这个编码问题?



感谢您的帮助!



我的项目




  • Rails 5.0.1

  • Ruby 2.3.3

  • Inky-rb 宝石(邮件的基础模板渲染器)


解决方案

我终于找到了我的问题。这是来自 inky-rb 宝石,它有一些问题可以理解编码。



我只是重命名我的布局(或模板),如下所示:

 #app / views / layouts 
default.text.inky#=> default.text.erb


I am building a Rails application and am face of a problem with my text mailer: I can’t find how to make special character (é, è, à, …) to be encoded properly.
It works great with html mailer because I can set the <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> but that’s not possible with text mailer.

Example of issue in text mailer (my_mailer.text.erb)

D&#233;monstration # Démonstration

Extract of my mailer:

mail from: <from>,
     to: <to>,
     subject: <subject>,
     body: <body>

I also tried to add charset: 'utf-8' property to the mail method without success either. How can I fix this encoding issue ?

Thanks for your help !

My project:

  • Rails 5.0.1
  • Ruby 2.3.3
  • Inky-rb gem (Foundation template renderer for mailers)

解决方案

I finally found my issue. It was coming from the inky-rb gem which has some problem to understand encoding.

I just rename my layout (or template) like this:

# app/views/layouts  
default.text.inky # => default.text.erb

这篇关于Rails:邮件和文本部分的UTF-8编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆