Upgrade Rails from 7.1 to 7.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 7.1 to version 7.2 .
- 1. Preparations
- 2. Ruby Version
- 3. Gems
- 4. Config Files
- 5. Rails Guides
- 6. Notable New Features
- 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. We do have an article for strategies on upgrading with low test coverage as well.
- Have a staging environment that is as similar as possible to production, so that proper QA can be completed.
- 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 refer to our Solving Dual Booting Issues when Changes aren’t Backwards Compatible article.
For full details check out our article on How to Prepare Your App for a Rails Upgrade .
2. Ruby Version
Previously, Rails has only dropped compatability with older Ruby versions with the release of a new major version. With Rails 7.2 comes a big change that will now see EOL Ruby versions dropped with the release of minor versions as well. This is to avoid the complications involved in maintaining compatibilities with unsupported versions of Ruby.
For the Rails 7.2 release, Ruby 3.1 is the required minimum version
Check out our Ruby & Rails Compatibility Table to see all the required Ruby versions across all Rails versions.
3. Gems
Make sure you check the GitHub page of the gems currently installed in your application for more information about compatibility with Rails 7.2. If you are the maintainer of the gem, you’ll need to make sure it supports Rails 7.2.
A great tool to checkout gems compatibility is RailsBump .
We also encourage you to use the next-rails gem to run bundle_report outdated for more information on gems that will require an update. Check out our article on The Next Rails Gem to learn more.
4. Config Files
Rails includes the rails app:update task .
You can use this task as a guideline as explained thoroughly by this Revisiting rails:update blog post.
As an alternative, check out RailsDiff , which provides an overview of the changes in a basic Rails app between 7.1.x and 7.2.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 New Features
- Development Container Configurations: Rails 7.2 adds the ability to generate a development container configuration for new and existing Rails applications that will include a
.devcontainerdirectory with the following files:- Dockerfile,
- docker-compose.yml
- devcontainer.json
-
Browser Version Guarding: Rails will now allow specifications regarding what browser versions can be granted accessibility as well as limiting browser versions to actions with the allow_browser method.
-
Progressive Web Application Files (PWA) will be generated by default, served from
app/views/pwaand can be dynamically served from ERB files. -
Omakase RubuCop rules: Rails applications will by default be configured with a set of rules defined by rubocop-rails-omakase
-
GitHub CI workflow: New applications will come equipped and ready with Github CI workflows, making it easier to begin with automated scanning, linting, and testing.
-
Brakeman: Along with the Github CI workflows, all new applications will also include Brakeman by default to help continuously scan for possible security vulnerabilities.
- YJIT is now enabled by default for new applications running on Ruby 3.3+
7. Application Code
If you have ignored deprecation warnings on past version jumps, and haven’t stayed 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. The following is a list of the removals in Rails 7.2.
7.1 Railties
- Remove deprecated
Rails::Generators::Testing::Behaviour. - Remove deprecated
Rails.application.secrets. - Remove deprecated
Rails.config.enable_dependency_loading. - Remove deprecated
find_cmd_and_execconsole helper. - Remove support for oracle, sqlserver, and JRuby specific database adapters from the new and
db:system:changerails commands. - Remove
config.public_file_server.enabledoption from the generators. - See full list of changes in the changelog
7.2 Action Pack
- Remove deprecated constant
ActionDispatch::IllegalStateError. - Remove deprecated constant
AbstractController::Helpers::MissingHelperError. - Remove deprecated comparison between
ActionController::ParametersandHash. - Remove deprecated
Rails.application.config.action_dispatch.return_only_request_media_type_on_content_type. - Remove deprecated
speaker,vibrate, andvrpermissions policy directives. - Remove deprecated support to set
Rails.application.config.action_dispatch.show_exceptionstotrueandfalse. - See full list of changes in the changelog
7.3 Action View
- Remove deprecated
@rails/ujsin favor of Turbo. - See full list of changes in the changelog
7.4 Action Mailer
- Remove deprecated
config.action_mailer.preview_path. - Remove deprecated params via
:argsforassert_enqueued_email_with. - See full list of changes in the changelog
7.5 Active Record
The public signature for the serialize method changes between Rails 7.1 and 7.2.
This works in Rails 7.1:
serialize :report, JSON
However, it will raise this deprecation warning:
DEPRECATION WARNING: Passing the coder as positional argument is deprecated and
will be removed in Rails 7.2.
Please pass the coder as a keyword argument
If you want to keep that behavior and avoid an exception with Rails 7.2, you will need to change it to:
serialize :report, coder: JSON
The default serialization behavior for a column is to use YAML as the coder. That means that if you define a serialized attribute without explicitly specifying a coder, Rails will serialize and deserialize data using the YAML format.
Here is a list of other removals from the Rails 7.2 release notes :
- Remove deprecated
Rails.application.config.active_record.suppress_multiple_database_warning. - Remove deprecated support to call
alias_attributewith non-existent attribute names. - Remove deprecated
nameargument fromActiveRecord::Base.remove_connection. - Remove deprecated
ActiveRecord::Base.clear_active_connections!. - Remove deprecated
ActiveRecord::Base.clear_reloadable_connections!. - Remove deprecated
ActiveRecord::Base.clear_all_connections!. - Remove deprecated
ActiveRecord::Base.flush_idle_connections!. - Remove deprecated
ActiveRecord::ActiveJobRequiredError. - Remove deprecated support to define
explainin the connection adapter with 2 arguments. - Remove deprecated
ActiveRecord::LogSubscriber.runtime method. - Remove deprecated
ActiveRecord::LogSubscriber.runtime= method. - Remove deprecated
ActiveRecord::LogSubscriber.reset_runtime method. - Remove deprecated
ActiveRecord::Migration.check_pending method. - Remove deprecated support to passing
SchemaMigrationandInternalMetadataclasses as arguments toActiveRecord::MigrationContext. - Remove deprecated behavior to support referring to a singular association by its plural name.
- Remove deprecated
TestFixtures.fixture_path. - Remove deprecated support to
ActiveRecord::Base#read_attribute(:id)to return the custom primary key value. - Remove deprecated
#all_foreign_keys_valid?from database adapters. - Remove deprecated
ActiveRecord::ConnectionAdapters::SchemaCache.load_from. - Remove deprecated
ActiveRecord::ConnectionAdapters::SchemaCache#data_sources. - Remove deprecated
#all_connection_pools. - Remove deprecated support to apply
#connection_pool_list,#active_connections?,#clear_active_connections!,#clear_reloadable_connections!,#clear_all_connections!and#flush_idle_connections!to the connections pools for the current role when theroleargument isn’t provided. - Remove deprecated
ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass. - Remove deprecated
#quote_bound_value. - Remove deprecated support to quote
ActiveSupport::Duration. - Remove deprecated support to pass
deferrable: truetoadd_foreign_key. - Remove deprecated support to pass
rewheretoActiveRecord::Relation#merge. - Remove deprecated behavior that would rollback a transaction block when exited using
return,breakorthrow. - See full list of changes in the changelog
7.6 Active Storage
- Remove deprecated
config.active_storage.replace_on_assign_to_many. - Remove deprecated
config.active_storage.silence_invalid_content_types_warning. - See full list of changes in the changelog
7.7 Active Support
- Remove deprecated
ActiveSupport::Notifications::Event#childrenandActiveSupport::Notifications::Event#parent_of?. - Remove deprecated support to call the following methods without passing a deprecator:
deprecatedeprecate_constantActiveSupport::Deprecation::DeprecatedObjectProxy.newActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.newActiveSupport::Deprecation::DeprecatedConstantProxy.newassert_deprecatedassert_not_deprecatedcollect_deprecations
- Remove deprecated
ActiveSupport::Deprecationdelegation to instance. - Remove deprecated
SafeBuffer#clone_empty. - Remove deprecated
#to_default_sfromArray,Date,DateTimeandTime. - Remove deprecated
:pool_sizeand:pool_timeoutoptions for the cache storage. - Remove deprecated support for
config.active_support.cache_format_version = 6.1. - Remove deprecated constants
ActiveSupport::LogSubscriber::CLEARandActiveSupport::LogSubscriber::BOLD. - Remove deprecated support to bolding log text with positional boolean in
ActiveSupport::LogSubscriber#color. - Remove deprecated
config.active_support.disable_to_s_conversion. - Remove deprecated
config.active_support.remove_deprecated_time_with_zone_name. - Remove deprecated
config.active_support.use_rfc4122_namespaced_uuids. - Remove deprecated support to passing
Dalli::Clientinstances toMemCacheStore. - See full list of changes in the changelog
7.8 Active Job
- Remove deprecated primitive serializer for
BigDecimalarguments. - Remove deprecated support to set numeric values to
scheduled_atattribute. - Remove deprecated
:exponentially_longervalue for the:waitinretry_on. - 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.2!
If you find yourself in need of assistance or your team doesn’t have the time to tackle these challenges, you can always contact us. Our experts are here to help you navigate the upgrade process and ensure your Rails application continues to thrive.
Download our free eBook: The Complete Guide to Upgrade Rails .