Search code examples
ruby-on-railstemplatesencodingutf-8mailer

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


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)

Solution

  • 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