Viren
Viren

Reputation: 5962

Using Non English character resulting in unexpected error in Rails 3.2 application

Well this is weird let me describe the scenario

I have this mailer define for my rails application

class DeliveryMail < ActionMailer::Base
  default from: "[email protected]"

  def document_upload_mail(user,document)
     @user = user
     @document = document
     mail(:to => user.email ,:subject =>  "Envió de enlace descarga documentos resultados domain") do |format|
      format.html { render "upload_file" }
     end
  end
end

Now the problem is this spanish text

Envió de enlace descarga documentos resultados domain

Whenever I set this as subject of the mail

:subject => "Envió de enlace descarga documentos resultados domain"

This is the error Rails prompt with my console

syntax error, unexpected $end, expecting ')'

Now If I remove the text "Envió" Rails dont throw any error and mail get delivered

Just to Let you know I not missing any syntax any where

pasting the mail code

class DeliveryMail < ActionMailer::Base
  default from: "[email protected]"

  def user_creation_mail(user,password)
    @user = user
    @password = password
    mail(:to => user.email,:subject => "Congratulation you been registered in Domain") do |format|
      format.html { render "user_creation" }
    end
  end


  def document_upload_mail(user,document)
     @user = user
     @document = document
     mail(:to => user.email ,:subject =>  "Envió de enlace descarga documentos resultados domain") do |format|
      format.html { render "upload_file" }
     end
  end
end

Not Sure what wrong with these

I created a dummy rails application to check to see I the same behavior is shared across

and Yes I found the same error in this application as well

My Rails version is

3.2.1

Ruby version

1.9.2-p290

Sure there is something wrong can anyone guide me on this

Upvotes: 2

Views: 280

Answers (2)

jdoe
jdoe

Reputation: 15771

Try:

# coding: utf-8

Just put coding: in your first-line comment and then after an optional whitespace specify the encoding of the rest of your file. You can put extra explanation here, like:

# I will use the following encoding: utf-8. Till the end of the file.

See? coding: part is here, so it works.

Upvotes: 1

Dty
Dty

Reputation: 12273

Put this at the very top of your DeliveryMail class. Or anywhere else the special characters are present.

# encoding: UTF-8

I had a similar problem with Chinese characters in my app and adding this line of code fixed the problem for me.

Upvotes: 2

Related Questions