DO NOT READ THIS FILE ON GITHUB, GUIDES ARE PUBLISHED ON https://guides.rubyonrails.org.
Highlights in Rails 6.1:
- Per-database Connection Switching
- Horizontal Sharding
- Strict Loading Associations
- Delegated Types
- Destroy Associations Async
These release notes cover only the major changes. To learn about various bug fixes and changes, please refer to the changelogs or check out the list of commits in the main Rails repository on GitHub.
If you're upgrading an existing application, it's a great idea to have good test coverage before going in. You should also first upgrade to Rails 6.0 in case you haven't and make sure your application still runs as expected before attempting an update to Rails 6.1. A list of things to watch out for when upgrading is available in the Upgrading Ruby on Rails guide.
Rails 6.1 provides you with the ability to switch connections per-database. In 6.0 if you switched to the reading role then all database connections also switched to the reading role. Now in 6.1 if you set legacy_connection_handling to false in your configuration, Rails will allow you to switch connections for a single database by calling connected_to on the corresponding abstract class.
Rails 6.0 provided the ability to functionally partition (multiple partitions, different schemas) your database but wasn't able to support horizontal sharding (same schema, multiple partitions). Rails wasn't able to support horizontal sharding because models in Active Record could only have one connection per-role per-class. This is now fixed and horizontal sharding with Rails is available.
Strict loading associations allows you to ensure that all your associations are loaded eagerly and stop N+1's before they happen.
Delegated Types is an alternative to single-table inheritance. This helps represent class hierarchies allowing the superclass to be a concrete class that is represented by its own table. Each subclass has its own table for additional attributes.
Destroy associations async adds the ability for applications to destroy associations in a background job. This can help you avoid timeouts and other performance issues in your application when destroying data.
Please refer to the Changelog for detailed changes.
-
Remove deprecated
rake notestasks. -
Remove deprecated
connectionoption in therails dbconsolecommand. -
Remove deprecated
SOURCE_ANNOTATION_DIRECTORIESenvironment variable support fromrails notes. -
Remove deprecated
serverargument from the rails server command. -
Remove deprecated support for using the
HOSTenvironment variable to specify the server IP. -
Remove deprecated
rake dev:cachetasks. -
Remove deprecated
rake routestasks. -
Remove deprecated
rake initializerstasks.
Please refer to the Changelog for detailed changes.
Please refer to the Changelog for detailed changes.
-
Remove deprecated
ActionDispatch::Http::ParameterFilter. -
Remove deprecated
force_sslat the controller level.
- Deprecate
config.action_dispatch.return_only_media_type_on_content_type.
- Change
ActionDispatch::Response#content_typeto return the full Content-Type header.
Please refer to the Changelog for detailed changes.
-
Remove deprecated
escape_whitelistfromActionView::Template::Handlers::ERB. -
Remove deprecated
find_all_anywherefromActionView::Resolver. -
Remove deprecated
formatsfromActionView::Template::HTML. -
Remove deprecated
formatsfromActionView::Template::RawFile. -
Remove deprecated
formatsfromActionView::Template::Text. -
Remove deprecated
find_filefromActionView::PathSet. -
Remove deprecated
rendered_formatfromActionView::LookupContext. -
Remove deprecated
find_filefromActionView::ViewPaths. -
Remove deprecated support to pass an object that is not a
ActionView::LookupContextas the first argument inActionView::Base#initialize. -
Remove deprecated
formatargumentActionView::Base#initialize. -
Remove deprecated
ActionView::Template#refresh. -
Remove deprecated
ActionView::Template#original_encoding. -
Remove deprecated
ActionView::Template#variants. -
Remove deprecated
ActionView::Template#formats. -
Remove deprecated
ActionView::Template#virtual_path=. -
Remove deprecated
ActionView::Template#updated_at. -
Remove deprecated
updated_atargument required onActionView::Template#initialize. -
Remove deprecated
ActionView::Template.finalize_compiled_template_methods. -
Remove deprecated
config.action_view.finalize_compiled_template_methods -
Remove deprecated support to calling
ActionView::ViewPaths#with_fallbackwith a block. -
Remove deprecated support to passing absolute paths to
render template:. -
Remove deprecated support to passing relative paths to
render file:. -
Remove support to template handlers that don't accept two arguments.
-
Remove deprecated pattern argument in
ActionView::Template::PathResolver. -
Remove deprecated support to call private methods from object in some view helpers.
-
Require that
ActionView::Basesubclasses implement#compiled_method_container. -
Make
localsargument required onActionView::Template#initialize. -
The
javascript_include_tagandstylesheet_link_tagasset helpers generate aLinkheader that gives hints to modern browsers about preloading assets. This can be disabled by settingconfig.action_view.preload_links_headertofalse.
Please refer to the Changelog for detailed changes.
- Remove deprecated
ActionMailer::Base.receivein favor of Action Mailbox.
Please refer to the Changelog for detailed changes.
-
Remove deprecated methods from
ActiveRecord::ConnectionAdapters::DatabaseLimits.column_name_lengthtable_name_lengthcolumns_per_tableindexes_per_tablecolumns_per_multicolumn_indexsql_query_lengthjoins_per_query -
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?. -
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?. -
Remove deprecated
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?. -
Remove deprecated
ActiveRecord::Base#update_attributesandActiveRecord::Base#update_attributes!. -
Remove deprecated
migrations_pathargument inActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version. -
Remove deprecated
config.active_record.sqlite3.represent_boolean_as_integer. -
Remove deprecated methods from
ActiveRecord::DatabaseConfigurations.fetcheachfirstvalues[]= -
Remove deprecated
ActiveRecord::Result#to_hashmethod. -
Remove deprecated support for using unsafe raw SQL in
ActiveRecord::Relationmethods.
-
Deprecate
ActiveRecord::Base.allow_unsafe_raw_sql. -
Deprecate
databasekwarg onconnected_to. -
Deprecate
connection_handlerswhenlegacy_connection_handlingis set to false.
-
MySQL: Uniqueness validator now respects default database collation, no longer enforce case-sensitive comparison by default.
-
relation.createdoes no longer leak scope to class-level querying methods in initialization block and callbacks.Before:
User.where(name: "John").create do |john| User.find_by(name: "David") # => nil end
After:
User.where(name: "John").create do |john| User.find_by(name: "David") # => #<User name: "David", ...> end
-
Named scope chain does no longer leak scope to class-level querying methods.
class User < ActiveRecord::Base scope :david, -> { User.where(name: "David") } end
Before:
User.where(name: "John").david # SELECT * FROM users WHERE name = 'John' AND name = 'David'
After:
User.where(name: "John").david # SELECT * FROM users WHERE name = 'David'
-
where.notnow generates NAND predicates instead of NOR.Before:
User.where.not(name: "Jon", role: "admin") # SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
After:
User.where.not(name: "Jon", role: "admin") # SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
-
To use the new per-database connection handling applications must change
legacy_connection_handlingto false and remove deprecated accessors onconnection_handlers. Public methods forconnects_toandconnected_torequire no changes.
Please refer to the Changelog for detailed changes.
-
Remove deprecated support to pass
:combine_optionsoperations toActiveStorage::Transformers::ImageProcessing. -
Remove deprecated
ActiveStorage::Transformers::MiniMagickTransformer. -
Remove deprecated
config.active_storage.queue. -
Remove deprecated
ActiveStorage::Downloading.
- Deprecate
Blob.create_after_uploadin favor ofBlob.create_and_upload. (Pull Request)
- Add
Blob.create_and_uploadto create a new blob and upload the givenioto the service. (Pull Request) ActiveStorage::Blob#service_namecolumn was added. It is required that a migration is run after the upgrade. Runbin/rails app:updateto generate that migration.
Please refer to the Changelog for detailed changes.
- Active Model's errors are now objects with an interface that allows your application to more easily handle and interact with errors thrown by models. The feature includes a query interface, enables more precise testing, and access to error details.
Please refer to the Changelog for detailed changes.
-
Remove deprecated fallback to
I18n.default_localewhenconfig.i18n.fallbacksis empty. -
Remove deprecated
LoggerSilenceconstant. -
Remove deprecated
ActiveSupport::LoggerThreadSafeLevel#after_initialize. -
Remove deprecated
Module#parent_name,Module#parentandModule#parents. -
Remove deprecated file
active_support/core_ext/module/reachable. -
Remove deprecated file
active_support/core_ext/numeric/inquiry. -
Remove deprecated file
active_support/core_ext/array/prepend_and_append. -
Remove deprecated file
active_support/core_ext/hash/compact. -
Remove deprecated file
active_support/core_ext/hash/transform_values. -
Remove deprecated file
active_support/core_ext/range/include_range. -
Remove deprecated
ActiveSupport::Multibyte::Chars#consumes?andActiveSupport::Multibyte::Chars#normalize. -
Remove deprecated
ActiveSupport::Multibyte::Unicode.pack_graphemes,ActiveSupport::Multibyte::Unicode.unpack_graphemes,ActiveSupport::Multibyte::Unicode.normalize,ActiveSupport::Multibyte::Unicode.downcase,ActiveSupport::Multibyte::Unicode.upcaseandActiveSupport::Multibyte::Unicode.swapcase. -
Remove deprecated
ActiveSupport::Notifications::Instrumenter#end=.
- Deprecate
ActiveSupport::Multibyte::Unicode.default_normalization_form.
Please refer to the Changelog for detailed changes.
- Deprecate
config.active_job.return_false_on_aborted_enqueue.
- Return
falsewhen enqueuing a job is aborted.
Please refer to the Changelog for detailed changes.
-
Add method to confirm rich text content existence by adding
?after name of the rich text attribute. (Pull Request) -
Add
fill_in_rich_text_areasystem test case helper to find a trix editor and fill it with given HTML content. (Pull Request) -
Add
ActionText::FixtureSet.attachmentto generate<action-text-attachment>elements in database fixtures. (Pull Request)
Please refer to the Changelog for detailed changes.
- Deprecate
Rails.application.credentials.action_mailbox.api_keyandMAILGUN_INGRESS_API_KEYin favor ofRails.application.credentials.action_mailbox.signing_keyandMAILGUN_INGRESS_SIGNING_KEY.
Please refer to the Changelog for detailed changes.
See the full list of contributors to Rails for the many people who spent many hours making Rails, the stable and robust framework it is. Kudos to all of them.