Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby 1.9.3 UndefinedConversionError

Up until recently everything was working fine on my machines but since a few days I keep getting an error Encoding::UndefinedConversionError: U+2713 from UTF-8 to US-ASCII any time I post something from the browser to the server.

First since posts were involved I tried the most obvious thing with adding encoding to the database.yml:

development:
  adapter: postgresql
  hostname: localhost
  port: 5432
  username: mikael
  password:
  database: dev
  encoding: utf8

If I install ruby-debug19 and ruby-debug-base19 and run rails with:

rails s --environment=development --debug

Now everything is working fine. How the hell am I supposed to find out the cause of the problem so that I may fix it?

EDIT 1:

1.9.3p0 :001 > Encoding.default_internal
 => #<Encoding:UTF-8> 
1.9.3p0 :002 > Encoding.default_external
 => #<Encoding:UTF-8> 

EDIT 2: If I run in production mode everything works fine.

like image 372
mhenrixon Avatar asked Jan 28 '12 10:01

mhenrixon


2 Answers

Try setting LC_ALL and LANG variable in your shell. Add these lines to your ~/.profile, ~/.bash_profile, ~/.zprofile or somewhere similar - depending on your system.

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

You can get a list of all locales by running locale -a. At the end you should see something similar when you run locale in a new terminal window:

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
like image 100
Lenart Avatar answered Oct 25 '22 09:10

Lenart


I had this problem today. My LC_ALL was blank but everything else looked correct according to Lenart's answer. Changing LC_ALL did not fix it for me either.

The solution for my project was to update rspec from 2.14.6 to 2.14.7.

like image 41
davidkovsky Avatar answered Oct 25 '22 07:10

davidkovsky