I’ve just upgraded an old Ruby on Rails 3.0 project to the current 3.1 build. Having expected ours of pain I was very pleased to discover that it’s all terribly easy. Here’s the step by step (as ever YMMV depending on gems you have installed).
- Open your gemfile and replace gem ‘rails’, ‘3.0.0’ with gem ‘rails’, ‘3.1.3’. 3.1.3 being the latest build at the time of writing.
- If you want to use the new asset pipeline hotness in 3.1 (and why wouldn’t you?) you need to add a new section at the bottom of the file:
group :assets do gem 'sass-rails', " ~> 3.1.0" gem 'coffee-rails', "~> 3.1.0" gem 'uglifier' end
- Now open up your command line and run a bundle install. You may need to delete gemfile.lock.
- The Rails update will generate a bunch of conflicts. I did the following (make sure you use the diff option to check for yourself!):
- boot.rb – overwrite.
- routes.rb – do not overwrite.
- application.rb – do not overwrite. We’ll patch this up manually next.
- development.rb – do not overwrite. You might be able to get away with overwriting this, but I have settings I need in here.
- production.rb – do no overwrite. Again, I have settings I need in here.
- test.rb – overwrite. I didn’t have any special settings here, but use the diff to check yours!
- secret_token.rb – overwrite.
- session_store.rb – overwrite.
- en.yml – do not overwrite.
- Now we need to make a few changes that would have been made if we let Rails overwrite our files. Open up config/application.rb and add the following:
# Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0'
- Open up config/environments/development.rb, remove “config.action_view.debug_rjs = true”and add the following:
# Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true
- Open up config/environments/production.rb and add:
- You’ll have to do some work to cleanup your assets and how they are included in your layouts – but that’s very much an exercise for the reader :)