OmbuLabs Blog

The Lean Software Boutique

Upgrade Rails from 5.1 to 5.2

This article is part of our Upgrade Rails series. To see more of them, click here.

This article will cover the most important aspects that you need to know to get your Ruby on Rails application from version 5.1 to 5.2.

  1. Ruby version
  2. Gems
  3. Config files
  4. Application code
    1. Active Storage
    2. Credentials
  5. Next steps

1. Ruby version

Like Rails 5.0 and 5.1, Rails 5.2 requires at least Ruby 2.2.2.

2. Gems

At the time of writing, the Rails 5.2 release is relatively recent, which means that some gems may still not be fully compatible, or contain deprecation warnings if you're not using their latest version. Ready4Rails can help you check if the gem is compatible with Rails 5.0, but it may have annoying bugs/deprecation warnings on 5.2. Some (popular) gem examples are:

3. Config files

Rails includes the rails app:update task. You can use this task as a guideline as explained thoroughly in this post.

As an alternative, check out RailsDiff, which provides an overview of the changes in a basic Rails app between 5.1.x and 5.2.x (or any other source/target versions).

4. Application code

There were not too many deprecations between 5.1 and 5.2 compared to past releases (see the full changelog here).

However, one major feature is the introduction of ActiveStorage.

a. Active Storage

Active Storage is a replacement for Paperclip and other gems, like Shrine. Paperclip in particular has been deprecated. If you're using Paperclip, the maintainers wrote an in-depth migration guide which you can follow here.

b. Credentials

Another major feature is the introduction of Credentials. It will eventually replace the current config/secrets.yml. Since there are also encrypted secrets (config/secrets.yml.enc), its intention is to clear up the confusion.

Your private credentials will reside in config/credentials.yml.enc, a file that can be safely committed into your repository (its contents are encrypted). To un-encrypt them, there's a master key (config/master.key) which should NOT be in your repository (it's git-ignored by default if you start a new Rails 5.2 app). To edit the credentials, you don't directly access credentials.yml.enc, instead, there's a bin/rails credentials:edit task which opens an unencrypted version of the file (as long as you have the master key).

One controversial aspect of it is the cross-environment credential sharing, the credentials file will keep all of your development, test and production keys. For more information on Credentials and a work-around to this last issue, check out this post, where they use Hash#dig to configure per-environment credentials.

5. Next steps

If you successfully followed all of these steps, you should now be running Rails 5.2! Do you have any other useful tips or recommendations? Did we miss anything? Share them with us in the comments section.

If you don't have the time to upgrade your Rails app, check out our Ruby on Rails upgrade service: FastRuby.io