1

Incompatible character encodings: UTF-8 and ASCII-8BIT

How can I solve this error on Rails 3.2.3 and Ruby 1.9.3?

I tried to put these two lines in the environment.rb:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

I am sure that application.rb also contains this line "config.encoding = "utf-8".

Does anyone know how to solve this?

1
  • 3
    Where do you actually get these errors?
    – Cubic
    Sep 17, 2012 at 12:05

2 Answers 2

0

Consider using so called magic comments on the first line of your .rb file with encoding:

# encoding: UTF-8

class Xyz
    ...
end

It is very important in files where you place text with accents and other non-ASCII characters. They are the primary cause of the error you mention.

Sometimes it may happen that you mistype a character and, instead of a letter, you insert a hidden symbol. Also check your file for these. Look at the line ends and in spaces.

0
0

If you have data to store on the hdd, you can try data.force_encoding('UTF-8').

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.