Login

Top 5 tips for upgrading Rails to Ruby 1.9

Posted by Steve Quinlan on January 06 2010 @ 10:23

[Warning, this is a programmer post. It gets Blurby!]

We’ve upgraded almost all of our applications to Rails 2.3.5 and Ruby 1.9. All things said, it was not easy.

So here are my top 5 tips for upgrading your Rails applications to use Ruby 1.9

The MySQL Ruby Gem

If you use MySQL, use this mysql-ruby fork by  Loren Segal. It wouldn’t install as a gem so I downloaded the code from GitHub and turned it into a gem. Email me if you want the gem.

The MySQL Database

The columns and tables in our databases had to be converted to UTF-8. These commands came in handy

/* Here's 1 command altering a table, and 2 commands altering the first 2 fields in that table */
alter table users character set utf8;
alter table users modify email varchar(255) character set utf8 collate utf8_unicode_ci;
alter table users modify crypted_password varchar(255) character set utf8 collate utf8_unicode_ci;
/* etc.... */

Then I put these lines in my.cnf

[mysqld]
init-connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci

UTF-8 + Rails + Ruby 1.9

Watch for UTF-8/ASCII problems. In combination with the above, I would advise

  • Putting # coding utf-8 at the top of your ruby code
  • Putting these lines into your environment.rb

Encoding.default_internal = 'utf-8'

Encoding.default_external = 'utf-8'

Maintaining Multiple Ruby versions

Use Ruby Version Manager. This is very useful if, like me, you have a number of Ruby 1.8 and Ruby 1.9 applications running. Ruby Switcher makes it easy to install new Ruby VM’s and switch between them.  Note, it installs Ruby 1.9 off your home directory. Edit the script to change this.

Test

All of our applications have a healthy mixture of Test Unit tests, and Selenium tests. Converting to 1.9 would have been terrifying without this safety net.  It’s been said enough already, but if you’re not testing your code, I would advise that you start now.

If you’ve any questions about converting your Rails applications to Ruby 1.9, just email me or comment below.

0 comment(s)

Leave a comment