RoR + MySQL + Unicode

hello! I have a problem when I want to display data in Unicode from
database. I read this
tutorial
but I still have problem with non-English characters. I
don’t have any other idea what I should do. Did you meet with similat
problem? Have you got any idea? Thanks in advance.

Hi, Agnieszka,

have you made sure that you’ve got and encoding: utf8 directive in your
database.yaml config file?

Cheers,
Jan

hello!
Yes, I’m sure. My database.yml file looks like:

development:
adapter: mysql
database: ***
encoding: utf8
username: ***
password: ***
host: ***
port: ***

etc…
but is it possible that problem lies in fact that my database in on Unix
environment but I work on Windows. May this connection cause a special
probelem?
I look for special coding, parameters in Ruby source but I find nothing.

Hi,

just another guess: Have you installed the mysql gem on your windows
box?

gem install mysql

Cheers,
Jan

Are you testing the application in webrick?
If it’s load webrick with the option -c utf-8 (ruby script/server -c
utf-8)

Another thing that you can try is in your templates put the next:

.... ....

it’s redundant(theoretically), but in some cases it’s ok.

Regards

View this message in context:
http://www.nabble.com/RoR-%2B-MySQL-%2B-Unicode-tf1991783.html#a5487770
Sent from the RubyOnRails Users forum at Nabble.com.

Thanks for advice!
… but my application doesn’t display non-English characters. I
installed mysql gem and try charset iso-8859-1. Nothing …
I use text_field_with_auto_complete and there I display data from
database. May it cause problem? And when application display data from
database method find(:all) is executed? I decoded data in database as
utf-8 and I read data in utf-8 coding.
Are used special codings from reading from database to display in
application?
Thanks.

I had similar problems, and after trying everything…

I noticed that the problem was my database client… I mean, I used the
windows “console” to execute the mysql client for loading the data and
special characters displayed a ‘?’ on my browser, but when I used a rake
task to load data, special characters were displayed correctly.

I don’t know why… but I worked for me… I hope it helps you…

Try using an encoding of chaset uft-8, that may work. As long as your
database is set to work with utf-8 and you also have this set in your
database yml file this should (theoretically) work.

  • Sarah