Forum: Ruby on Rails Mailer template encoding error ( Spanish characters) not valid US-ASCII (obviously).

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-03-17 19:08
(Received via mailing list)
Some of my Mailer templates are in spanish, I get this error message :
action_view/template/handlers/erb.rb:129:in `valid_encoding': Your
template was not saved as valid US-ASCII. Please either specify US-
ASCII as the encoding for your template in your text editor, or mark
the template with its encoding by inserting the following as the first
line of the template: (ActionView::Template::Error)

# encoding: <name of correct encoding>.

The source of your template was:

Recibes este mensaje porque has mandado un email a <%= @receiver %>
Estamos actualizando la cantidad de registraciones regaladas.

I coded the Notifier like this :

class Notifier < ActionMailer::Base
  default :charset => "utf-8"
        mail(:to => destination, :subject => subject, :from => from)
do |format|
          format.text(:content_transfer_encoding => "base64")
          format.html(:content_transfer_encoding => "base64")

but this doesn't get rid of the error....  how & where  should I write
the encoding information
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2011-03-17 19:55
(Received via mailing list)
On Mar 17, 6:07pm, Erwin <> wrote:
> but this doesn't get rid of the error.... how & where should I write
> the encoding information

That's something else, it sets charset header on the outgoing message.
What ruby 1.9 is complaining about is the encoding of your erb file.
You need to do what the rails error message says and stick

<%# encoding: utf-8 %>

on the first line of your template (assuming utf-8 is what your
template is written in)

Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-03-18 08:03
(Received via mailing list)
Thanks Fred

you mean it's a Ruby 1.9 issue, not Rails... ( this is why I could not
find any doc on it in Rails API... maybe )
and of course it happen only in plain-text template...

I still do not understand why this error raised only when the script
was run from the cron task ... and never when running the script from
the command-line in the remote server console....   any idea on that ?
Ee0293412faca21e4ebf3326ed9d5f8c?d=identicon&s=25 Kad Kerforn (kadoudal)
on 2011-03-18 08:21
(Received via mailing list)
I read this post in forum, lot of info ... thanks
it's solved now ....
This topic is locked and can not be replied to.