Upgrade Rails from 3.1 to 3.2

Upgrade Rails from 3.1 to 3.2

This is part of our Upgrade Rails series opens a new window . We will be covering the most important aspects that you need to know to update your Ruby on Rails opens a new window application from version 3.1 opens a new window to 3.2 opens a new window .

  1. Considerations
  2. Ruby version
  3. Tools
  4. Config files
  5. Gemfile
  6. Deprecations
  7. Next steps

1. Considerations

Before beginning with the upgrade process, we recommend that each version of your Rails app has the latest patch version opens a new window before moving to the next major/minor version. For example, in order to follow this article, your Rails version opens a new window 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 opens a new window 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 opens a new window . The minor Ruby version that you can use is 1.8.7 opens a new window , and the latest one is 2.2 opens a new window . As always, we recommend you to use the latest version to avoid any bugs or vulnerabilities.

3. Tools

Rails 3.2 comes with a generator opens a new window 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 opens a new window makes that easy.

4. Config files

There are a few settings that you need to add to your environment filters

  • Add to config/environments/development.rb
# 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 config/environments/test.rb
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict

5. Gemfile

  • 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

6. Deprecations

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 opens a new window 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 opens a new window .

Get the book