What Is New in Ruby on Rails 7.0
| Category | Highlights |
|---|---|
| Improvements | Sprockets optional, button_to infers HTTP verb, interval columns return ActiveSupport::Duration, early-return transaction blocks now roll back, merge conditions consistently replace earlier clauses. |
| Breaking Changes | Removal of many deprecated configs (e.g., ActionDispatch::Response.return_only_media_type_on_content_type), ActionMailer::DeliveryJob removed in favor of ActionMailer::MailDeliveryJob, numerous ActiveRecord rake tasks and methods deleted, ActionMailbox credentials removed. |
| Deprecations | Tasks::DatabaseTasks.schema_file_type deprecated, passing format to #to_s deprecated (use #to_fs), config.active_support.disable_to_s_conversion introduced, other minor deprecations across ActiveSupport and ActiveJob. |
How does Rails 7 treat the asset pipeline and Sprockets?
In Rails 7 the asset pipeline is no longer a hard dependency; Sprockets is optional.
If your application still relies on Sprockets, add the explicit gem to your Gemfile:
gem "sprockets-rails"
Without this line the rails gem will not pull in sprockets-rails, keeping the boot time lean for API-only or Hotwire-centric apps.
What are the most impactful Active Record changes in Rails 7?
Rails 7 introduces several behavior changes that affect how queries and transactions work.
- Interval columns now return
ActiveSupport::Durationobjects. To retain the old string behavior, declare the attribute as:stringin the model. - Transaction blocks that return early are now rolled back. Previously an early return would commit the transaction, which could hide timeout-related bugs.
- Merge conditions on the same column now replace the earlier condition. The
rewhere: trueoption is no longer needed.
Example of the new merge behavior:
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
How has Action View's button_to helper been enhanced in Rails 7?
In Rails 7 button_to can infer the HTTP verb from an Active Record object used in the URL.
Before:
<input type="hidden" name="_method" value="post" autocomplete="off" />
After:
<input type="hidden" name="_method" value="patch" autocomplete="off" />
Usage example:
button_to("Do a POST", [:do_post_action, Workshop.find(1)])
This reduces boilerplate when building RESTful forms that target a specific record.
Which deprecated APIs were removed in Rails 7 and what should I replace them with?
Rails 7 removed a large set of deprecated APIs; most of them have direct modern equivalents or are simply no longer needed.
ActionDispatch::Response.return_only_media_type_on_content_type- no replacement; the default behavior is now always applied.ActionMailer::DeliveryJobandActionMailer::Parameterized::DeliveryJob- useActionMailer::MailDeliveryJobinstead.- Various
ActiveRecord::Baseconfiguration methods (e.g.,allow_unsafe_raw_sql,configurations.to_h) - rely on the newActiveRecord::DatabaseConfigurationsAPI. - Deprecated rake tasks such as
db:schema:load_if_ruby- use the standarddb:schema:loadtask. - ActionMailbox credentials like
Rails.application.credentials.action_mailbox.mailgun_api_key- configure the provider directly via environment variables.
Removing these calls and updating to the new APIs will prevent NameError exceptions during boot.
Frequently Asked Questions
What should I do before upgrading an existing app to Rails 7?
Run the full test suite, upgrade first to Rails 6.1, fix any deprecation warnings, then proceed with the Rails 7 upgrade.
How can I re-enable Sprockets if my app still needs it?
Add gem "sprockets-rails" to your Gemfile and run bundle install.
How do I keep interval columns as strings after the upgrade?
Declare the attribute in the model with attribute :column, :string.
What is the new job class for delivering mail in Rails 7?
Use ActionMailer::MailDeliveryJob instead of the removed ActionMailer::DeliveryJob.
Which config option replaces the removed config.active_support.use_sha1_digests?
There is no direct replacement; SHA-1 digests are no longer supported.
How do I silence the new #to_s deprecation warnings?
Set config.active_support.disable_to_s_conversion = true in your application config.