Hi,
I have problem with showing some string in my site with Rails 4
I get this message:
incompatible character encodings: ASCII-8BIT and UTF-8 concerning this html sequence in an erb file:
<%= MyString.to_s.force_encoding("UTF-8") %>
I get this problem only on **production server,** but I do not have the problem on my local computer
What can I do with this problem
It is coming from an hypertable database, the sring is logged well wih the word written with accent
I use the same database with my local computer without problem, I have the poblem only on production server
Hi,
I have problem with showing some string in my site with Rails 4
I get this message:
incompatible character encodings: ASCII-8BIT and UTF-8
concerning this html sequence in an erb file:
<h3><%= MyString.to_s.force_encoding("UTF-8") %></h3>
I get this problem only on production server, but I do not have the problem on my local computer
What can I do with this problem
At the top of this erb file, add the line:
# encoding: UTF-8
Make sure it is the very first line of the file. This will force the Ruby interpreter to read the page as unicode, no matter what format the file may actually be saved in (or mistaken for).
I assume you have created a “dump” of the data from production and copied it to your local MySQL version.
Also I assume you are comparing the same records on dev & production (“comparing apples to apples”)
Check the character set (also known as “encoding”) and collation settings on the table (on both your dev and production database) to make sure they are the same.
Note that these are set on a table-by-table basis. Because MySQL was originally invented in Sweden, the historical default for the character encoding is utf8_sweedish_ci. Typically people change that to utf8_unicode_ci
Once you verify they are identical on both machines, if you want to fix them on Production you’ll want to use a Rails migration.