Home |  MySQL Buzz |  FAQ |  Feeds |  Submit your blog feed |  Feedback |  Archive |  Aggregate feed RSS 2.0 English Deutsch Español Français Italiano 日本語 Русский Português 中文
Encoding and JRuby on Rails
+0 Vote Up -0 Vote Down

Studing JRuby and Rails I faced some encoding problems. The solution was very easy. First you must have to create your database using utf8 character set. In case you are using MySQL, just do the following:

CREATE DATABASE `yourdatabasename` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

or

ALTER DATABASE yourdatabasename CHARACTER SET utf8 COLLATE utf8_general_ci;

If you already have a database with records, read this post from @akitaonrails.

In my case, I’m using the activerecord-jdbc-adapter gem, and connecting to the database through the MySQL JDBC Connector (http://www.mysql.com/downloads/connector/j/).

At this time, I just have downloaded the JDBC driver (.jar file), and copied to $JRUBY_HOME/lib folder (if you are using RVM, find the JRuby installation folder using the rvm debug or rvm info command).

Lastly, I just have set the following parameters into connection string (in database.yml file):

jdbc:mysql://localhost:3306/yourdatabasename?characterSetResults=UTF-8&characterEncoding=UTF-8&useUnicode=yes

Maybe this will be useful to someone.

Votes:

You must be logged in with a MySQL account to vote on Planet MySQL entries. More information on PlanetMySQL voting.

Planet MySQL © 1995, 2014, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.