Migrating to Rails 3 for Heroku Bamboo

Recently there were some interesting “updates to the Heroku infrastructure”:http://blog.heroku.com/archives/2010/3/5/public_beta_deployment_stacks/, giving the opportunity to migrate “my personal Rails 2 website”:http://www.phoet.de/ to “Rails 3 (beta)”:http://weblog.rubyonrails.org/2010/2/5/rails-3-0-beta-release/.

Having an app with only a single model “for caching data”:http://blog.nofail.de/2010/02/simple-db-caching-for-heroku/, there is no worry about database migration. A nice opportunity for starting out new:

rvm use 1.9.1
gem install rails --pre
rails basement-rails3
cd basement-rails3
heroku create basement-rails3 --stack bamboo-mri-1.9.1

h2. business as usual?

Not really… Having “Yehuda Katz”:http://yehudakatz.com/ as a core developer of Rails 3, it’s no surprise they adopted the “Merb”:http://merbivore.com/ approach of just using one executable for everything. So the ‘script’ folder now contains just a ‘rails’ script. Creating controllers, running the server, jumping into the console – all through the ‘rails’ command:

rails -h
=> [...]
=>  generate    Generate new code (short-cut alias: "g")
=>  console     Start the Rails console (short-cut alias: "c")
=>  server      Start the Rails server (short-cut alias: "s")
=> [...]

I appreciate the shortcuts! No more discussions about what shortcut to use for ‘script/server’ (ss is not an option in germany…)!

h2. dependency management

Rails 3 has changed the way of working with gems. It uses “bundler”:http://github.com/carlhuda/bundler/ to deal with dependencies. Beeing a big fan of Java’s dependency management tools like “Ivy”:http://ant.apache.org/ivy/ or “Maven”:http://maven.apache.org/, I think that separating out the dependency issue is good idea.

All dependencies are now defined in a separate ‘Gemfile’ using an easy dsl to manage the gems:

gem "rails", "3.0.0.beta"
gem "sqlite3-ruby", :require => "sqlite3"
group :test do
  gem "test-unit", "1.2.3"

I had some trouble getting bundler working on my machine, but after reinstalling Rails 3 AFTER the bundler gem, everything worked fine.

The only Rails plugin in my app is “Haml”:http://haml-lang.com/ and I was confident that it would play well with the latest Rails version. Never the less I was pleased to find “RailsPlugins.org”:http://www.railsplugins.org/ where one can check the compatibility of plugins with Rails 3.

h2. escaping vs. html_safe

There were just very little changes to the existing codebase in my application. Despite one thing though, that forced changes to nearly all of the wrapper objects that are used to encapsulate the data that is coming from external services like “twitter”:http://twitter.com/phoet/. The Problem is that “Rails 3 has a strict way of dealing with escaping”:http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/. Every string rendered into the view will be escaped unless it is ‘html_safe’. Since my application is using a lot of pregenerated content with inline html, adding ‘html_safe’ markers is inevitable:

  def content

h2. Ruby 1.9 is different

The biggest pile of migration problems resulted from using Ruby 1.9.1. The latest Ruby version is a lot faster, but it has changed some of the core functionality. The ‘enum_with_index’ method for example is replaced with an ‘each_with_index’ method on a hash.
Using old YAML files resulted in some strange behavior as these files have changed format slightly (because of the new symbol style that Ruby 1.9 is using, I guess):

# old
  id: home
# new
  :id: home

Ruby 1.9 also changed the way of handling unicode characters. Using these in code forces the developer to put a “magic comment”:http://blog.grayproductions.net/articles/ruby_19s_three_default_encodings/ in the first line of the ruby file:

# coding: utf-8

h2. beta quirks

Most of the new Rails 3 stuff just works, but there are some reasons why it is still beta:

# rails console won't quit with controll-c but exits without error typing ö.ö
rails c
=> Loading development environment (Rails 3.0.0.beta)
ruby-1.9.1-p378 > ö.ö

# rails help doesn't work for commands
rails -h
=> [...]
=> All commands can be run with -h for more information.
rails generate -h
=> Could not find generator -h.

“Beta but running!”:http://basement-rails3.heroku.com/

1 thought on “Migrating to Rails 3 for Heroku Bamboo

  1. Pingback: Tweets die Migrating to Rails 3 for Heroku Bamboo | #nofail erwähnt -- Topsy.com

Comments are closed.