Upgrade Rails from 6.1 to 7.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 6.1 to version 7.0 .
- 1. Preparations
- 2. Ruby version
- 3. Gems
- 4. Config files
- 5. Rails Guides
- 6. Notable Changes
- 7. Application code
- 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 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 . Find out more about how and why to dual boot .
- To learn more about dual booting with non-backwards compatible changes you can visit this article .
For full details check out our article on How to Prepare Your App for a Rails Upgrade .
2. Ruby version
Rails 7.0 requires Ruby 2.7 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 7.0. In case you are the maintainer of the gem, you’ll need to make sure it supports Rails 7.0 and if it doesn’t, update it. A great tool to checkout gems compatibility is RailsBump .
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 6.1.x and 7.0.x (or any other source/target versions).
5. Rails Guides
It is important to check through the official Rails Guides and follow any of the steps necessary for your application.
6. Notable Changes
-
Zeitwerk: if your application still runs in classic mode you’ll need to switch to zeitwerk mode . There is also no configuration point to set the autoloading mode,
config.autoloader=
has been deleted. If you had it set to:zeitwerk
, just remove it. Check our this article that we wrote about the Zeitwerk upgrade. -
Spring: If your application uses Spring, it needs to be upgraded to at least version 3.0.0, otherwise you’ll get
undefined method 'mechanism=' for ActiveSupport::Dependencies:Module
-
Sprockets is now an optional dependency: Rails doesn’t depend on sprockets-rails anymore. You’ll need to explicitly add the dependency if your application still needs to use Sprockets. If you are looking to migrate your javaScript code from sprockets to Webpacker, take a look at this blogpost .
7. Application code
If you have ignored deprecation warnings on past version jumps, and haven’t been staying up to date with them you may find that you have issues with broken tests or broken parts of the application. If you have trouble figuring out why something is broken it may be because a deprecation is removed, so you can check through this list to see if this may be the case.
7.1 Railties
- Remove deprecated
config
indbconsole
.
7.2 Action Pack
- Remove deprecated
return_only_media_type_on_content_type
inActionDispatch::Response
. - Remove deprecated
hosts_response_app
inRails.config.action_dispatch
. - Remove deprecated
#host!
inActionDispatch::SystemTestCase
. - Remove deprecated support to passing a
path
tofixture_file_upload
relative tofixture_path
. - See full list of changes in the changelog .
7.3 Action View
-
Remove deprecated
raise_on_missing_translations
inRails.config.action_view
. -
The
ActionView::Helpers::UrlHelper#button_to
changed the behavior. Starting from Rails 7.0 this method renders a form tag with patch HTTP verb if a persisted Active Record object is used to build button URL.
7.4 Action Mailer
-
Remove deprecated
ActionMailer::DeliveryJob
andActionMailer::Parameterized::DeliveryJob
in favor ofActionMailer::MailDeliveryJob
. -
The
email_address_with_name
method now returns just the address if name is blank. -
The default values for both
open_timeout
andread_timeout
was configured to 5 in the SMTP Settings. -
See full list of changes in the changelog
7.5 Active Record
-
Remove deprecated
database
kwarg fromconnected_to
. -
Remove deprecated
allow_unsafe_raw_sql
inActiveRecord::Base
. -
Remove deprecated option
:spec_name
inconfigs_for
. -
Remove deprecated support to YAML load
ActiveRecord::Base
instance in the Rails 4.2 and 4.1 formats. -
Remove deprecation warning when
:interval
column is used in PostgreSQL database. Now, interval columns will returnActiveSupport::Duration
objects instead of strings. - Remove deprecated rake tasks:
db:schema:load_if_ruby
db:structure:dump
db:structure:load
db:structure:load_if_sql
db:structure:dump:#{name}
db:structure:load:#{name}
db:test:load_structure
db:test:load_structure:#{name}
-
Rollback transactions when the block returns earlier than expected: Before this change, when a transaction block returned early, the transaction would be committed. The problem is that timeouts triggered inside the transaction block was also making the incomplete transaction to be committed, so in order to avoid this mistake, the transaction block is rolled back.
-
Merging conditions on the same column no longer maintain both conditions, and will be consistently replaced by the latter condition.
- See full list of changes in the changelog
7.6 Active Storage
-
Adds the
ActiveStorage::Blob.compose
to concatenate multiple blobs. -
Setting custom metadata on blobs are now persisted to remote storage.
-
Support direct uploads to multiple services.
- Support transforming empty-ish
has_many_attached
value into [] (e.g. [””]).@user.highlights = [""] @user.highlights # => []
-
Invalid default content types are deprecated: blobs created with content_type
image/jpg
,image/pjpeg
,image/bmp
,text/javascript
will now produce a deprecation warning, since these are not valid content types. -
Remove deprecated
replace_on_assign_to_many
inconfig.active_storage
. -
Remove deprecated
build_after_upload
in favor ofcreate_after_upload!
. -
Remove deprecated
service_url
in favor ofurl
. - See full list of changes in the changelog .
7.7 Active Model
-
Remove deprecated enumeration of
ActiveModel::Errors
instances as a Hash. -
Remove deprecated
to_h
,slice!
,values
,keys
andto_xml
inActiveModel::Errors
. -
Remove deprecated support concat errors to
ActiveModel::Errors#messages
. -
Remove deprecated support to clear errors from
ActiveModel::Errors#messages
. -
Remove deprecated support to delete errors from
ActiveModel::Errors#messages
. -
Remove deprecated support to use []= in
ActiveModel::Errors#messages
.
7.8 Active Support
-
Remove deprecated
use_sha1_digests
inconfig.active_support
. -
Remove deprecated
URI.parser
. -
Remove deprecated
include?
inRange
. -
Remove deprecated
default_normalization_form
inActiveSupport::Multibyte::Unicode
. -
Remove deprecated support to delete errors from
ActiveModel::Errors#messages
. -
Remove deprecated support to use []= in
ActiveModel::Errors#messages
. -
See full list of changes in the changelog .
7.9 Active Job
Removed deprecated behavior that was not halting after_enqueue/after_perform callbacks when a previous callback was halted with throw :abort.
-
Remove deprecated
:return_false_on_aborted_enqueue
option. -
Remove deprecated
ActiveRecord::Base.connection_config
. -
Remove deprecated
ActiveRecord::Base.arel_attribute
. -
Remove deprecated
ActiveRecord::Base.configurations.default_hash
. -
Remove deprecated
ActiveRecord::Base.configurations.to_h
. -
Remove deprecated
ActiveRecord::Result#map! and ActiveRecord::Result#collect!
. -
Remove deprecated
ActiveRecord::Base#remove_connection
. -
See full list of changes in the changelog .
7.10 Action Text
-
Make the Action Text + Trix JavaScript and CSS available through the asset pipeline.
-
OpenSSL constants are now used for Digest computations.
-
Allow passing in a custom
direct_upload_url
orblob_url_template
torich_text_area_tag
. -
See full list of changes in the changelog .
7.11 Action Mailbox
-
Add
attachments
to the list of permitted parameters for inbound emails conductor -
Add ability to configure ActiveStorage service for storing email raw source.
-
Add ability to incinerate an inbound message through the conductor interface.
-
See full list of changes in the changelog .
8. Next steps
If you successfully followed all of these steps, you should now be running Rails 7.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.1 yet, we can help! Download our free eBook: The Complete Guide to Upgrade Rails .