Upgrade Rails from 5.2 to 6.0
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.2 to 6.0 .
1. Preparations
Before beginning with the upgrade process, we have some recommended preparations:
- Your Rails app should have the latest patch version 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 .
- Create a dual boot mechanism, the fastest way to do this is installing the handy gem next_rails .
For full details check out our article on How to Prepare Your App for a Rails Upgrade .
2. Ruby version
Rails 6.0 requires Ruby 2.5 or later. Check out this table to see all the required Ruby versions across all Rails versions.
3. Gems
Make sure you check the Github page of the gems you use for the project to find out its compatibility with Rails 6.0. In case you own the gem, you’ll need to make sure it supports Rails 6.0 and if it doesn’t, update it.
4. 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.2.x and 6.0.x (or any other source/target versions).
5. Removals
Railties
-
Remove deprecated
after_bundle
helper inside plugins templates. -
Remove deprecated support to
config.ru
that uses the application class as argument ofrun
. -
Remove deprecated
environment
argument from the rails commands. -
Remove deprecated
capify!
method in generators and templates. -
Remove deprecated
config.secret_token
.
Action Pack
-
Remove deprecated
fragment_cache_key
helper in favor ofcombined_fragment_cache_key
. -
Remove deprecated methods in
ActionDispatch::TestResponse: #success?
in favor of#successful?
,#missing?
in favor of#not_found?
,#error?
in favor of#server_error
?
Action View
-
Remove deprecated
image_alt
helper. -
Remove an empty
RecordTagHelper
module from which the functionality was already moved to therecord_tag_helper
gem.
Active Record
-
Remove deprecated
#set_stat
from the transaction object. -
Remove deprecated
#supports_statement_cache?
from the database adapters. -
Remove deprecated
#insert_fixtures
from the database adapters. -
Remove deprecated
ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?
. -
Remove support for passing the column name to
sum
when a block is passed. -
Remove support for passing the column name to
count
when a block is passed. -
Remove support for delegation of missing methods in a relation to arel.
-
Remove support for delegating missing methods in a relation to private methods of the class.
-
Remove support for specifying a timestamp name for #cache_key.
-
Remove deprecated
ActiveRecord::Migrator.migrations_path=
. -
Remove deprecated
expand_hash_conditions_for_aggregates
.
6. Webpacker
Webpacker is now the default JavaScript compiler for Rails 6. You can still manage your JavaScript using the Asset Pipeline but it might be a good idea to start migrating to Webpack.
There is a really good screencast that explains everything about it: How to Use Javascript via Webpacker in Rails 6
7. Credentials
Rails 6 adds support for multi environment credentials. That means that now you can run rails credentials:edit --environment staging
and it will create a config/credentials/staging.yml.enc
file where you can store your encrypted credentials for staging (or whatever environment you want).
Rails will know which credential file should use based on the format of the file. Also, if you create an environment credential file, it will take precedence over the default config/credentials.yml.enc
.
8. Next steps
If you successfully followed all of these steps, you should now be running Rails 6.0! Do you have any other useful tips or recommendations? Did we miss anything important? Share them with us in the comments section.
If you’re not on Rails 6.0 yet, we can help! Download our free eBook: The Complete Guide to Upgrade Rails .