Ruby On Nails
Ruby On Nails

Reputation: 33

display unicode text with ruby on rails

I am reading (mysql) data to display on the view using ruby on rails. Everything is displayed fine, only the text is not in unicode, there are some text that are written in my native language and they can't be displayed correctly, all those letters are re-marked as question marks.

Upvotes: 1

Views: 531

Answers (2)

Alex Teut
Alex Teut

Reputation: 844

Ruby default charset is UTF-8. So:

  • if you have permissions to convert your database to UTF-8, do it.
  • else use iconv after receiving data from database to convert it from your mysql encoding to UTF-8.

And, by the way, if you read something from text files, utf-8 is not default charset(I still don't understand why). If you store in text files something but code, add

 # encoding: UTF-8

at the start of the file.

Upvotes: 0

Sergey K
Sergey K

Reputation: 5107

You have to change default MySQL charset and collation through the MySQL console. Here's the simple guide how to do that: http://www.devcha.com/2008/03/convert-existing-mysql-database-from.html

Upvotes: 1

Related Questions