Upgrade Rails from 5.1 to 5.2

Upgrade Rails from 5.1 to 5.2

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

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

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

1. Preparations

Before beginning with the upgrade process, we have some recommended preparations:

  • Your Rails app should have the latest patch version opens a new window before you move to the next major/minor version.
  • You should have at least 80% test coverage unless you have a dedicated QA team.
  • Follow a Git flow workflow to actively manage at least two environments: staging and production.
  • Check your Gemfile.lock for incompatibilities by using RailsBump opens a new window .
  • Create a dual boot mechanism, the fastest way to do this is installing the handy gem next_rails opens a new window .

For full details check out our article on How to Prepare Your App for a Rails Upgrade opens a new window .

2. Ruby version

Like Rails 5.0 and 5.1, Rails 5.2 opens a new window requires at least Ruby 2.2.2 opens a new window .

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

4. Config files

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

As an alternative, check out RailsDiff opens a new window , 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).

5. Application code

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

However, one major feature is the introduction of ActiveStorage opens a new window .

a. Active Storage

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

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 opens a new window , 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 opens a new window , where they use Hash#dig to configure per-environment credentials.

6. 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’re not on Rails 5.2 yet, we can help! Download our free eBook: The Complete Guide to Upgrade Rails opens a new window .

Get the book