Rails: UTF-8 encoding issue with mailer and text partials

夙愿已清 提交于 2019-12-02 18:22:51

问题


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)

回答1:


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


来源:https://stackoverflow.com/questions/41432693/rails-utf-8-encoding-issue-with-mailer-and-text-partials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!