UTF8 Database content

Hi,

Forgive me if this is a basic question. I am using rails and simply
trying to get content stored and retrieved from the database in UTF8 (i
am using arabic). When the data is stored it ends up as ???
question marks. I have set the database charset and the table to UTF8.

Any help appreciated.

Abdulaziz

Forgive me if this is a basic question. I am using rails and simply
trying to get content stored and retrieved from the database in UTF8 (i
am using arabic). When the data is stored it ends up as ???
question marks. I have set the database charset and the table to UTF8.

This should interest you.

http://woss.name/2006/10/25/migrating-your-rails-application-to-unicode/

I just ran into similar problems Abdulaziz. I wrote an import script
that imports data from files into the database. The problem was that
the files were in one encoding (windows-1252) and the database in utf8.

I used the ‘iconv’ library which is available in standard Ruby to
convert the file to utf8 first before attempting to put the data into my
models and save them to the database. (On Windows I believe iconv is
only available in the One-Click installer version of Ruby).

If it is MySQL at least, you can make sure Rails is talking to the
database correctly by adding the “encoding” line to database.yml like
this:

development:
adapter: mysql
database: adatabase
encoding: utf8
username: auser
password: apassword
host: localhost

(Be sure to restart Rails after adding this)

If the data is coming from the browser then you need to make sure the
data is being sent correctly. If you are using MySQL you should also
think about installing PHPMyAdmin and checking with that that the data
is being stored properly, as it might just be a display problem.

Also make sure that any templates of pages being sent out to the browser
have the line:

in the and that it is the very first entry.

Hope this helps and good luck.

Chad.