Upgrade Rails from 6.1 to 7.0

Upgrade Rails from 6.1 to 7.0

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 6.1 opens a new window to version 7.0 opens a new window .

  1. 1. Preparations
  2. 2. Ruby version
  3. 3. Gems
  4. 4. Config files
  5. 5. Rails Guides
  6. 6. Notable Changes
  7. 7. Application code
  8. 8. Next steps

1. Preparations

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

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

2. Ruby version

Rails 7.0 requires Ruby 2.7 opens a new window or later. Check out this table opens a new window 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 opens a new window .

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

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 in dbconsole.
7.2 Action Pack
  • Remove deprecated return_only_media_type_on_content_type in ActionDispatch::Response.
  • Remove deprecated hosts_response_app in Rails.config.action_dispatch.
  • Remove deprecated #host! in ActionDispatch::SystemTestCase.
  • Remove deprecated support to passing a path to fixture_file_upload relative to fixture_path.
  • See full list of changes in the changelog opens a new window .
7.3 Action View
  • Remove deprecated raise_on_missing_translations in Rails.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 and ActionMailer::Parameterized::DeliveryJob in favor of ActionMailer::MailDeliveryJob.

  • The email_address_with_name method now returns just the address if name is blank.

  • The default values for both open_timeout and read_timeout was configured to 5 in the SMTP Settings.

  • See full list of changes in the changelog opens a new window

7.5 Active Record
  • Remove deprecated database kwarg from connected_to.

  • Remove deprecated allow_unsafe_raw_sql in ActiveRecord::Base.

  • Remove deprecated option :spec_name in configs_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 return ActiveSupport::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 opens a new window
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 in config.active_storage.

  • Remove deprecated build_after_upload in favor of create_after_upload!.

  • Remove deprecated service_url in favor of url.

  • See full list of changes in the changelog opens a new window .
7.7 Active Model
  • Remove deprecated enumeration of ActiveModel::Errors instances as a Hash.

  • Remove deprecated to_h, slice!, values, keys and to_xml in ActiveModel::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 in config.active_support.

  • Remove deprecated URI.parser.

  • Remove deprecated include? in Range.

  • Remove deprecated default_normalization_form in ActiveSupport::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 opens a new window .

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

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 or blob_url_template to rich_text_area_tag.

  • See full list of changes in the changelog opens a new window .

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

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

Get the book