1
votes

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?

2
Where do you actually get these errors?Cubic

2 Answers

0
votes

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
votes

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