Upgrade Rails from 3.1 to 3.2
Before beginning with the upgrade process, we recommend that each version of your Rails app has the latest patch version before moving to the next major/minor version. For example, in order to follow this article, your Rails version should be at 3.1.12 before updating to Rails 3.2.22
2. Ruby version
Depending on which patch version of Rails 3.2 you are using, the Ruby versions that you can use will change. Since we recommend you to always use the latest patch version, we will focus this article on Rails 3.2.22. The minor Ruby version that you can use is 1.8.7, and the latest one is 2.2. As always, we recommend you to use the latest version to avoid any bugs or vulnerabilities.
Rails 3.2 comes with a generator that helps you to update the configuration files. The
rake rails:update generator will identify every configuration file in your application that differs from a new Rails application. When it detects a conflict, it will offer to overwrite your file. Keep in mind that many of your files will be different because you’ve made changes from a default new Rails application. When the generator offers to overwrite a file, enter a
d in order to review the differences.
Sometimes it’s also useful to check which files changed between two specific versions of Rails. Fortunately Rails Diff makes that easy.
4. Config files
There are a few settings that you need to add to your environment filters
- Add to
# Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) config.active_record.auto_explain_threshold_in_seconds = 0.5
- Add to
# Raise exception on mass assignment protection for Active Record models config.active_record.mass_assignment_sanitizer = :strict
- You should update a couple of gems inside your assets group
gem "rails", "~> 3.2.0" group :assets do gem 'sass-rails', '~> 3.2.6' gem 'coffee-rails', '~> 3.2.2' gem 'uglifier', '>= 1.0.3' end
Rails 3.2 deprecates
vendor/plugins, and it’s the last Rails version that support it. If your plan is to migrate to Rails 4 in the future, you can start replacing any plugins by extracting them to gems and adding them to your
Gemfile, or you can move them into
lib/my_plugin/*. We cover this topic in depth in our Rails 4.0 upgrade guide.
7. Next steps
After you get your application properly running in Rails 3.2, you will probably want to keep working on this Rails upgrade journey. So don’t forget to check our complete Rails upgrade series to make that easy.
If you’re not on Rails 3.2 yet, we can help! Download our free eBook: The Complete Guide to Upgrade Rails.