Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid byte sequence in US-ASCII (Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper)

My setup is:

linux + Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper

I followed http://railscasts.com/episodes/194-mongodb-and-mongomapper, that everything is OK first. I can insert English strings successfully, but when I insert some Chinese strings, it inserted, but can't be displayed.

The web page shows an exception:

invalid byte sequence in US-ASCII 

I use mongo command to see the data in mongodb, and it's correct. But I don't know why rails can't display them.

thanks in advance

like image 778
Freewind Avatar asked Jul 07 '10 05:07

Freewind


2 Answers

Please add the following lines in your environment.rb .

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

The problem will be solved.

like image 94
Ramanavel Avatar answered Nov 09 '22 06:11

Ramanavel


You may correct this error writing this

export LC_ALL="en_US.UTF-8"

to your ~/.profile, ~/.bash_profile or similar. It works like a charm.

like image 18
agarie Avatar answered Nov 09 '22 05:11

agarie