Archive for the 'Ruby' Category

Ruby MySQL gem UTF-8

Monday, June 28th, 2010

I just spent a ton of time figuring this out, so I figured I’d toss it up on the blog in case someone else needs it.

Problem: I was exporting and manipulating the data in a MySQL database using the ruby mysql gem. Unfortunately, the people writing the data in the database were using curly quotes and other typographic marks that were causing trouble.

Solution:

require ‘rubygems’
require ‘mysql’

@dbh = Mysql.init
@dbh.options(Mysql::SET_CHARSET_NAME, ‘utf8′)
@dbh.real_connect(”localhost”,@dbuser,@dbpass,@dbname)

The key is to add a line in the options call to set the character set to UTF-8. This seems to solve the problem.

Hope this helps!

Boost Rails performance by generating constants

Thursday, March 11th, 2010

Make everything as simple as possible but no simpler

Tuesday, January 26th, 2010

How to prevent browsers from caching a page in Rails

Tuesday, April 14th, 2009

How to reload a class in irb

Tuesday, September 16th, 2008

Stack Overflow is pretty impressive

Tuesday, September 16th, 2008

How to test tag attributes using assert_select

Wednesday, September 10th, 2008