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

236 views
Skip to first unread message

Melb01

unread,
Nov 19, 2014, 7:50:00 AM11/19/14
to rubyonra...@googlegroups.com
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


regards,

Vladimir Gordeev

unread,
Nov 19, 2014, 8:49:05 AM11/19/14
to rubyonra...@googlegroups.com
Where this MyString comes from? Maybe your production and local databases configured to use different encodings.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/217f5775-1225-4759-84d5-b9a0d381aed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Melb01

unread,
Nov 19, 2014, 4:11:25 PM11/19/14
to rubyonra...@googlegroups.com
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

Vladimir Gordeev

unread,
Nov 19, 2014, 5:12:38 PM11/19/14
to rubyonra...@googlegroups.com
I didn't say that databases are different. I said that they could use different encodings.

On Wed, Nov 19, 2014 at 11:11 PM, Melb01 <melag...@gmail.com> wrote:
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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Walter Lee Davis

unread,
Nov 19, 2014, 9:14:19 PM11/19/14
to rubyonra...@googlegroups.com
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).

Walter

>
> regards,
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/217f5775-1225-4759-84d5-b9a0d381aed3%40googlegroups.com.

Melb01

unread,
Nov 20, 2014, 6:05:49 AM11/20/14
to rubyonra...@googlegroups.com
I add it to every file used for this template but  it didn't work

I was able to solve it using the method encode("utf-8", uttf-8") for the Mystring directly after the query from database and it worked

but i don"t understand why it worked normally on my local computer and coming from the same databse

rgds,

Vladimir Gordeev

unread,
Nov 20, 2014, 9:40:27 AM11/20/14
to rubyonra...@googlegroups.com
but i don"t understand why it worked normally on my local computer and coming from the same databse

 Dear sir, how do you define "same"? They could contain same data with different encodings.

Jason Fleetwood-Boldt

unread,
Nov 20, 2014, 1:10:17 PM11/20/14
to rubyonra...@googlegroups.com

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.

see also...



-Jason


On Nov 20, 2014, at 9:39 AM, Vladimir Gordeev <gordeev.v...@gmail.com> wrote:

but i don"t understand why it worked normally on my local computer and coming from the same databse

 Dear sir, how do you define "same"? They could contain same data with different encodings.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

----

Jason Fleetwood-Boldt

All material © Jason Fleetwood-Boldt 2014. Public conversations may be turned into blog posts (original poster information will be made anonymous). Email ja...@datatravels.com with questions/concerns about this.

Reply all
Reply to author
Forward
0 new messages