rails 6.1.0
Active Support
-
Ensure
MemoryStoredisables compression by default. Reverts behavior ofMemoryStoreto its prior rails5.1behavior.Max Gurewitz
-
Calling
iso8601on negative durations retains the negative sign on individual digits instead of prepending it.This change is required so we can interoperate with PostgreSQL, which prefers negative signs for each component.
Compatibility with other iso8601 parsers which support leading negatives as well as negatives per component is still retained.
Before:
(-1.year - 1.day).iso8601 # => "-P1Y1D"After:
(-1.year - 1.day).iso8601 # => "P-1Y-1D"Vipul A M
-
Remove deprecated
ActiveSupport::Notifications::Instrumenter#end=.Rafael Mendonça França
-
Deprecate
ActiveSupport::Multibyte::Unicode.default_normalization_form.Rafael Mendonça França
-
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.Rafael Mendonça França
-
Remove deprecated
ActiveSupport::Multibyte::Chars#consumes?andActiveSupport::Multibyte::Chars#normalize.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/range/include_range.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/hash/transform_values.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/hash/compact.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/array/prepend_and_append.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/numeric/inquiry.Rafael Mendonça França
-
Remove deprecated file
active_support/core_ext/module/reachable.Rafael Mendonça França
-
Remove deprecated
Module#parent_name,Module#parentandModule#parents.Rafael Mendonça França
-
Remove deprecated
ActiveSupport::LoggerThreadSafeLevel#after_initialize.Rafael Mendonça França
-
Remove deprecated
LoggerSilenceconstant.Rafael Mendonça França
-
Remove deprecated fallback to
I18n.default_localwhenconfig.i18n.fallbacksis empty.Rafael Mendonça França
-
Remove entries from local cache on
RedisCacheStore#delete_matchedFixes #38627
ojab
-
Speed up
ActiveSupport::SecurityUtils.fixed_length_secure_compareby usingOpenSSL.fixed_length_secure_compare, if available.Nate Matykiewicz
-
ActiveSupport::Cache::MemCacheStorenow checksENV["MEMCACHE_SERVERS"]before falling back to"localhost:11211"if configured without any addresses.config.cache_store = :mem_cache_store # is now equivalent to config.cache_store = :mem_cache_store, ENV["MEMCACHE_SERVERS"] || "localhost:11211" # instead of config.cache_store = :mem_cache_store, "localhost:11211" # ignores ENV["MEMCACHE_SERVERS"]Sam Bostock
-
ActiveSupport::Subscriber#attach_tonow accepts aninherit_all:argument. When set to true, it allows a subscriber to receive events for methods defined in the subscriber's ancestor class(es).class ActionControllerSubscriber < ActiveSupport::Subscriber attach_to :action_controller def start_processing(event) info "Processing by #{event.payload[:controller]}##{event.payload[:action]} as #{format}" end def redirect_to(event) info { "Redirected to #{event.payload[:location]}" } end end # We detach ActionControllerSubscriber from the :action_controller namespace so that our CustomActionControllerSubscriber # can provide its own instrumentation for certain events in the namespace ActionControllerSubscriber.detach_from(:action_controller) class CustomActionControllerSubscriber < ActionControllerSubscriber attach_to :action_controller, inherit_all: true def start_processing(event) info "A custom response to start_processing events" end # => CustomActionControllerSubscriber will process events for "start_processing.action_controller" notifications # using its own #start_processing implementation, while retaining ActionControllerSubscriber's instrumentation # for "redirect_to.action_controller" notifications endAdrianna Chang
-
Allow the digest class used to generate non-sensitive digests to be configured with
config.active_support.hash_digest_class.config.active_support.use_sha1_digestsis deprecated in favour ofconfig.active_support.hash_digest_class = ::Digest::SHA1.Dirkjan Bussink
-
Fix bug to make memcached write_entry expire correctly with unless_exist
Jye Lee
-
Add
ActiveSupport::Durationconversion methodsin_seconds,in_minutes,in_hours,in_days,in_weeks,in_months, andin_yearsreturn the respective duration covered.Jason York
-
Fixed issue in
ActiveSupport::Cache::RedisCacheStorenot passing options toread_multicausingfetch_multito not work properlyRajesh Sharma
-
Fixed issue in
ActiveSupport::Cache::MemCacheStorewhich caused duplicate compression, and caused the providedcompression_thresholdto not be respected.Max Gurewitz
-
Prevent
RedisCacheStoreandMemCacheStorefrom performing compression when reading entries written withraw: true.Max Gurewitz
-
URI.parseris deprecated and will be removed in Rails 6.2. UseURI::DEFAULT_PARSERinstead.Jean Boussier
-
require_dependencyhas been documented to be obsolete in:zeitwerkmode. The method is not deprecated as such (yet), but applications are encouraged to not use it.In
:zeitwerkmode, semantics match Ruby's and you do not need to be defensive with load order. Just refer to classes and modules normally. If the constant name is dynamic, camelize if needed, and constantize.Xavier Noria
-
Add 3rd person aliases of
Symbol#start_with?andSymbol#end_with?.:foo.starts_with?("f") # => true :foo.ends_with?("o") # => trueRyuta Kamizono
-
Add override of unary plus for
ActiveSupport::Duration.+ 1.secondis now identical to+1.secondto prevent errors where a seemingly innocent change of formatting leads to a change in the code behavior.Before:
+1.second.class # => ActiveSupport::Duration (+ 1.second).class # => IntegerAfter:
+1.second.class # => ActiveSupport::Duration (+ 1.second).class # => ActiveSupport::DurationFixes #39079.
Roman Kushnir
-
Add subsec to
ActiveSupport::TimeWithZone#inspect.Before:
Time.at(1498099140).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00 UTC +00:00" Time.at(1498099140, 123456780, :nsec).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00 UTC +00:00" Time.at(1498099140 + Rational("1/3")).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00 UTC +00:00"After:
Time.at(1498099140).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00.000000000 UTC +00:00" Time.at(1498099140, 123456780, :nsec).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00.123456780 UTC +00:00" Time.at(1498099140 + Rational("1/3")).in_time_zone.inspect # => "Thu, 22 Jun 2017 02:39:00.333333333 UTC +00:00"akinomaeni
-
Calling
ActiveSupport::TaggedLogging#taggedwithout a block now returns a tagged logger.logger.tagged("BCX").info("Funky time!") # => [BCX] Funky time!Eugene Kenny
-
Align
Range#cover?extension behavior with Ruby behavior for backwards ranges.(1..10).cover?(5..3)now returnsfalse, as it does in plain Ruby.Also update
#include?and#===behavior to match.Michael Groeneman
-
Update to TZInfo v2.0.0.
This changes the output of
ActiveSupport::TimeZone.utc_to_local, but can be controlled with theActiveSupport.utc_to_local_returns_utc_offset_timesconfig.New Rails 6.1 apps have it enabled by default, existing apps can upgrade via the config in config/initializers/new_framework_defaults_6_1.rb
See the
utc_to_local_returns_utc_offset_timesdocumentation for details.Phil Ross, Jared Beck
-
Add Date and Time
#yesterday?and#tomorrow?alongside#today?.Aliased to
#prev_day?and#next_day?to match the existing#prev/next_daymethods.Jatin Dhankhar
-
Add
Enumerable#pickto complementActiveRecord::Relation#pick.Eugene Kenny
-
[Breaking change]
ActiveSupport::Callbacks#halted_callback_hooknow receive a 2nd argument:ActiveSupport::Callbacks#halted_callback_hooknow receive the name of the callback being halted as second argument. This change will allow you to differentiate which callbacks halted the chain and act accordingly.class Book < ApplicationRecord before_save { throw(:abort) } before_create { throw(:abort) } def halted_callback_hook(filter, callback_name) Rails.logger.info("Book couldn't be #{callback_name}d") end Book.create # => "Book couldn't be created" book.save # => "Book couldn't be saved" endEdouard Chin
-
Support
prependwithActiveSupport::Concern.Allows a module with
extend ActiveSupport::Concernto be prepended.module Imposter extend ActiveSupport::Concern # Same as `included`, except only run when prepended. prepended do end end class Person prepend Imposter endClass methods are prepended to the base class, concerning is also updated:
concerning :Imposter, prepend: true do.Jason Karns, Elia Schito
-
Deprecate using
Range#include?method to check the inclusion of a value in a date time range. It is recommended to useRange#cover?method instead ofRange#include?to check the inclusion of a value in a date time range.Vishal Telangre
-
Support added for a
round_modeparameter, in all number helpers. (See:BigDecimal::mode.)number_to_currency(1234567890.50, precision: 0, round_mode: :half_down) # => "$1,234,567,890" number_to_percentage(302.24398923423, precision: 5, round_mode: :down) # => "302.24398%" number_to_rounded(389.32314, precision: 0, round_mode: :ceil) # => "390" number_to_human_size(483989, precision: 2, round_mode: :up) # => "480 KB" number_to_human(489939, precision: 2, round_mode: :floor) # => "480 Thousand" 485000.to_s(:human, precision: 2, round_mode: :half_even) # => "480 Thousand"Tom Lord
-
Array#to_sentenceno longer returns a frozen string.Before:
['one', 'two'].to_sentence.frozen? # => trueAfter:
['one', 'two'].to_sentence.frozen? # => falseNicolas Dular
-
When an instance of
ActiveSupport::Durationis converted to aniso8601duration string, ifweeksare mixed withdateparts, theweekpart will be converted to days. This keeps the parser and serializer on the same page.duration = ActiveSupport::Duration.build(1000000) # 1 week, 4 days, 13 hours, 46 minutes, and 40.0 seconds duration_iso = duration.iso8601 # P11DT13H46M40S ActiveSupport::Duration.parse(duration_iso) # 11 days, 13 hours, 46 minutes, and 40 seconds duration = ActiveSupport::Duration.build(604800) # 1 week duration_iso = duration.iso8601 # P1W ActiveSupport::Duration.parse(duration_iso) # 1 weekAbhishek Sarkar
-
Add block support to
ActiveSupport::Testing::TimeHelpers#travel_back.Tim Masliuchenko
-
Update
ActiveSupport::Messages::Metadata#fresh?to work for cookies with expiry set whenActiveSupport.parse_json_times = true.Christian Gregg
-
Support symbolic links for
content_pathinActiveSupport::EncryptedFile.Takumi Shotoku
-
Improve
Range#===,Range#include?, andRange#cover?to work with beginless (startless) and endless range targets.Allen Hsu, Andrew Hodgkinson
-
Don't use
Process#clock_gettime(CLOCK_THREAD_CPUTIME_ID)on Solaris.Iain Beeston
-
Prevent
ActiveSupport::Duration.build(value)from creating instances ofActiveSupport::Durationunlessvalueis of typeNumeric.Addresses the errant set of behaviours described in #37012 where
ActiveSupport::Durationcomparisons would fail confusingly or return unexpected results when comparing durations built from instances ofString.Before:
small_duration_from_string = ActiveSupport::Duration.build('9') large_duration_from_string = ActiveSupport::Duration.build('100000000000000') small_duration_from_int = ActiveSupport::Duration.build(9) large_duration_from_string > small_duration_from_string # => false small_duration_from_string == small_duration_from_int # => false small_duration_from_int < large_duration_from_string # => ArgumentError (comparison of ActiveSupport::Duration::Scalar with ActiveSupport::Duration failed) large_duration_from_string > small_duration_from_int # => ArgumentError (comparison of String with ActiveSupport::Duration failed)After:
small_duration_from_string = ActiveSupport::Duration.build('9') # => TypeError (can't build an ActiveSupport::Duration from a String)Alexei Emam
-
Add
ActiveSupport::Cache::Store#delete_multimethod to delete multiple keys from the cache store.Peter Zhu
-
Support multiple arguments in
HashWithIndifferentAccessformergeandupdatemethods, to follow Ruby 2.6 addition.Wojciech Wnętrzak
-
Allow initializing
thread_mattr_*attributes via:defaultoption.class Scraper thread_mattr_reader :client, default: Api::Client.new endGuilherme Mansur
-
Add
compact_blankfor those times when you want to remove #blank? values from an Enumerable (alsocompact_blank!on Hash, Array, ActionController::Parameters).Dana Sherson
-
Make ActiveSupport::Logger Fiber-safe.
Use
Fiber.current.__id__inActiveSupport::Logger#local_level=in order to make log level local to Ruby Fibers in addition to Threads.Example:
logger = ActiveSupport::Logger.new(STDOUT) logger.level = 1 puts "Main is debug? #{logger.debug?}" Fiber.new { logger.local_level = 0 puts "Thread is debug? #{logger.debug?}" }.resume puts "Main is debug? #{logger.debug?}"Before:
Main is debug? false Thread is debug? true Main is debug? trueAfter:
Main is debug? false Thread is debug? true Main is debug? falseFixes #36752.
Alexander Varnin
-
Allow the
on_rotationproc used when decrypting/verifying a message to be passed at the constructor level.Before:
crypt = ActiveSupport::MessageEncryptor.new('long_secret') crypt.decrypt_and_verify(encrypted_message, on_rotation: proc { ... }) crypt.decrypt_and_verify(another_encrypted_message, on_rotation: proc { ... })After:
crypt = ActiveSupport::MessageEncryptor.new('long_secret', on_rotation: proc { ... }) crypt.decrypt_and_verify(encrypted_message) crypt.decrypt_and_verify(another_encrypted_message)Edouard Chin
-
delegate_missing_towould raise aDelegationErrorif the object delegated to wasnil. Now theallow_niloption has been added to enable the user to specify they wantnilreturned in this case.Matthew Tanous
-
truncatewould return the original string if it was too short to be truncated and a frozen string if it were long enough to be truncated. Now truncate will consistently return an unfrozen string regardless. This behavior is consistent withgsubandstrip.Before:
'foobar'.truncate(5).frozen? # => true 'foobar'.truncate(6).frozen? # => falseAfter:
'foobar'.truncate(5).frozen? # => false 'foobar'.truncate(6).frozen? # => falseJordan Thomas
Active Model
-
Pass in
baseinstead ofbase_classto Error.human_attribute_nameThis is useful in cases where the
human_attribute_namemethod depends on other attributes' values of the class under validation to derive what the attribute name should be.Filipe Sabella
-
Deprecate marshalling load from legacy attributes format.
Ryuta Kamizono
-
*_previously_changed?accepts:fromand:tokeyword arguments like*_changed?.topic.update!(status: :archived) topic.status_previously_changed?(from: "active", to: "archived") # => trueGeorge Claghorn
-
Raise FrozenError when trying to write attributes that aren't backed by the database on an object that is frozen:
class Animal include ActiveModel::Attributes attribute :age end animal = Animal.new animal.freeze animal.age = 25 # => FrozenError, "can't modify a frozen Animal"Josh Brody
-
Add
*_previously_wasattribute methods when dirty tracking. Example:pirate.update(catchphrase: "Ahoy!") pirate.previous_changes["catchphrase"] # => ["Thar She Blows!", "Ahoy!"] pirate.catchphrase_previously_was # => "Thar She Blows!"DHH
-
Encapsulate each validation error as an Error object.
The
ActiveModel’serrorscollection is now an array of these Error objects, instead of messages/details hash.For each of these
Errorobject, itsmessageandfull_messagemethods are for generating error messages. Itsdetailsmethod would return error’s extra parameters, found in the originaldetailshash.The change tries its best at maintaining backward compatibility, however some edge cases won’t be covered, like
errors#firstwill returnActiveModel::Errorand manipulatingerrors.messagesanderrors.detailshashes directly will have no effect. Moving forward, please convert those direct manipulations to use provided API methods instead.The list of deprecated methods and their planned future behavioral changes at the next major release are:
errors#slice!will be removed.errors#eachwith thekey, valuetwo-arguments block will stop working, while theerrorsingle-argument block would returnErrorobject.errors#valueswill be removed.errors#keyswill be removed.errors#to_xmlwill be removed.errors#to_hwill be removed, and can be replaced witherrors#to_hash.- Manipulating
errorsitself as a hash will have no effect (e.g.errors[:foo] = 'bar'). - Manipulating the hash returned by
errors#messages(e.g.errors.messages[:foo] = 'bar') will have no effect. - Manipulating the hash returned by
errors#details(e.g.errors.details[:foo].clear) will have no effect.
lulalala
Active Record
-
Only warn about negative enums if a positive form that would cause conflicts exists.
Fixes #39065.
Alex Ghiculescu
-
Change
attribute_for_inspectto takefilter_attributesin consideration.Rafael Mendonça França
-
Fix odd behavior of inverse_of with multiple belongs_to to same class.
Fixes #35204.
Tomoyuki Kai
-
Build predicate conditions with objects that delegate
#idand primary key:class AdminAuthor delegate_missing_to :@author def initialize(author) @author = author end end Post.where(author: AdminAuthor.new(author))Sean Doyle
-
Add
connected_to_manyAPI.This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
Before:
AnimalsRecord.connected_to(role: :reading) do MealsRecord.connected_to(role: :reading) do Dog.first # read from animals replica Dinner.first # read from meals replica Person.first # read from primary writer end end
After:
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do Dog.first # read from animals replica Dinner.first # read from meals replica Person.first # read from primary writer end
Eileen M. Uchitelle, John Crepezzi
-
Add option to raise or log for
ActiveRecord::StrictLoadingViolationError.Some applications may not want to raise an error in production if using
strict_loading. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.Set
config.active_record.action_on_strict_loading_violationto:logerrors instead of raising.Eileen M. Uchitelle
-
Allow the inverse of a
has_oneassociation that was previously autosaved to be loaded.Fixes #34255.
Steven Weber
-
Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
This change reduces the chance of that happening by using the reference name, e.g.
index_my_table_on_my_reference.Fixes #38655.
Luke Redpath
-
MySQL: Uniqueness validator now respects default database collation, no longer enforce case sensitive comparison by default.
Ryuta Kamizono
-
Remove deprecated methods from
ActiveRecord::ConnectionAdapters::DatabaseLimits.column_name_lengthtable_name_lengthcolumns_per_tableindexes_per_tablecolumns_per_multicolumn_indexsql_query_lengthjoins_per_queryRafael Mendonça França
-
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?.Rafael Mendonça França
-
Remove deprecated
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?.Rafael Mendonça França
-
Remove deprecated
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?.Rafael Mendonça França
-
Remove deprecated
ActiveRecord::Base#update_attributesandActiveRecord::Base#update_attributes!.Rafael Mendonça França
-
Remove deprecated
migrations_pathargument inActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version.Rafael Mendonça França
-
Remove deprecated
config.active_record.sqlite3.represent_boolean_as_integer.Rafael Mendonça França
-
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 endAfter:
User.where(name: "John").create do |john| User.find_by(name: "David") # => #<User name: "David", ...> endRyuta Kamizono
-
Named scope chain does no longer leak scope to class level querying methods.
class User < ActiveRecord::Base scope :david, -> { User.where(name: "David") } endBefore:
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'Ryuta Kamizono
-
Remove deprecated methods from
ActiveRecord::DatabaseConfigurations.fetcheachfirstvalues[]=Rafael Mendonça França
-
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')Rafael Mendonça França
-
Remove deprecated
ActiveRecord::Result#to_hashmethod.Rafael Mendonça França
-
Deprecate
ActiveRecord::Base.allow_unsafe_raw_sql.Rafael Mendonça França
-
Remove deprecated support for using unsafe raw SQL in
ActiveRecord::Relationmethods.Rafael Mendonça França
-
Allow users to silence the "Rails couldn't infer whether you are using multiple databases..." message using
config.active_record.suppress_multiple_database_warning.Omri Gabay
-
Connections can be granularly switched for abstract classes when
connected_tois called.This change allows
connected_toto switch aroleand/orshardfor a single abstract class instead of all classes globally. Applications that want to use the new feature need to setconfig.active_record.legacy_connection_handlingtofalsein their application configuration.Example usage:
Given an application we have a
Usermodel that inherits fromApplicationRecordand aDogmodel that inherits fromAnimalsRecord.AnimalsRecordandApplicationRecordhave writing and reading connections as well as sharddefault,one, andtwo.ActiveRecord::Base.connected_to(role: :reading) do User.first # reads from default replica Dog.first # reads from default replica AnimalsRecord.connected_to(role: :writing, shard: :one) do User.first # reads from default replica Dog.first # reads from shard one primary end User.first # reads from default replica Dog.first # reads from default replica ApplicationRecord.connected_to(role: :writing, shard: :two) do User.first # reads from shard two primary Dog.first # reads from default replica end endEileen M. Uchitelle, John Crepezzi
-
Allow double-dash comment syntax when querying read-only databases
James Adam
-
Add
values_atmethod.Returns an array containing the values associated with the given methods.
topic = Topic.first topic.values_at(:title, :author_name) # => ["Budget", "Jason"]Similar to
Hash#values_atbut on an Active Record instance.Guillaume Briday
-
Fix
read_attribute_before_type_castto consider attribute aliases.Marcelo Lauxen
-
Support passing record to uniqueness validator
:conditionscallable:class Article < ApplicationRecord validates_uniqueness_of :title, conditions: ->(article) { published_at = article.published_at where(published_at: published_at.beginning_of_year..published_at.end_of_year) } endEliot Sykes
-
BatchEnumerator#update_allandBatchEnumerator#delete_allnow return the total number of rows affected, just like their non-batched counterparts.Person.in_batches.update_all("first_name = 'Eugene'") # => 42 Person.in_batches.delete_all # => 42Fixes #40287.
Eugene Kenny
-
Add support for PostgreSQL
intervaldata type with conversion toActiveSupport::Durationwhen loading records from database and serialization to ISO 8601 formatted duration string on save. Add support to define a column in migrations and get it in a schema dump. Optional column precision is supported.To use this in 6.1, you need to place the next string to your model file:
attribute :duration, :intervalTo keep old behavior until 6.2 is released:
attribute :duration, :stringExample:
create_table :events do |t| t.string :name t.interval :duration end class Event < ApplicationRecord attribute :duration, :interval end Event.create!(name: 'Rock Fest', duration: 2.days) Event.last.duration # => 2 days Event.last.duration.iso8601 # => "P2D" Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to databaseAndrey Novikov
-
Allow associations supporting the
dependent:key to takedependent: :destroy_async.class Account < ActiveRecord::Base belongs_to :supplier, dependent: :destroy_async end:destroy_asyncwill enqueue a job to destroy associated records in the background.DHH, George Claghorn, Cory Gwin, Rafael Mendonça França, Adrianna Chang
-
Add
SKIP_TEST_DATABASEenvironment variable to disable modifying the test database whenrails db:createandrails db:dropare called.Jason Schweier
-
connects_tocan only be called onActiveRecord::Baseor abstract classes.Ensure that
connects_tocan only be called fromActiveRecord::Baseor abstract classes. This protects the application from opening duplicate or too many connections.Eileen M. Uchitelle, John Crepezzi
-
All connection adapters
executenow raisesActiveRecord::ConnectionNotEstablishedrather thanActiveRecord::StatementInvalidwhen they encounter a connection error.Jean Boussier
-
Mysql2Adapter#quote_stringnow raisesActiveRecord::ConnectionNotEstablishedrather thanActiveRecord::StatementInvalidwhen it can't connect to the MySQL server.Jean Boussier
-
Add support for check constraints that are
NOT VALIDviavalidate: false(PostgreSQL-only).Alex Robbin
-
Ensure the default configuration is considered primary or first for an environment
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
Eileen M. Uchitelle
-
Allow
wherereferences association names as joined table name aliases.class Comment < ActiveRecord::Base enum label: [:default, :child] has_many :children, class_name: "Comment", foreign_key: :parent_id end # ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1 Comment.includes(:children).where("children.label": "child")Ryuta Kamizono
-
Support storing demodulized class name for polymorphic type.
Before Rails 6.1, storing demodulized class name is supported only for STI type by
store_full_sti_classclass attribute.Now
store_full_class_nameclass attribute can handle both STI and polymorphic types.Ryuta Kamizono
-
Deprecate
rails db:structure:{load, dump}tasks and extendrails db:schema:{load, dump}tasks to work with either:rubyor:sqlformat, depending onconfig.active_record.schema_formatconfiguration value.fatkodima
-
Respect the
selectvalues for eager loading.post = Post.select("UPPER(title) AS title").first post.title # => "WELCOME TO THE WEBLOG" post.body # => ActiveModel::MissingAttributeError # Rails 6.0 (ignore the `select` values) post = Post.select("UPPER(title) AS title").eager_load(:comments).first post.title # => "Welcome to the weblog" post.body # => "Such a lovely day" # Rails 6.1 (respect the `select` values) post = Post.select("UPPER(title) AS title").eager_load(:comments).first post.title # => "WELCOME TO THE WEBLOG" post.body # => ActiveModel::MissingAttributeErrorRyuta Kamizono
-
Allow attribute's default to be configured but keeping its own type.
class Post < ActiveRecord::Base attribute :written_at, default: -> { Time.now.utc } end # Rails 6.0 Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...> # Rails 6.1 Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>Ryuta Kamizono
-
Allow default to be configured for Enum.
class Book < ActiveRecord::Base enum status: [:proposed, :written, :published], _default: :published end Book.new.status # => "published"Ryuta Kamizono
-
Deprecate YAML loading from legacy format older than Rails 5.0.
Ryuta Kamizono
-
Added the setting
ActiveRecord::Base.immutable_strings_by_default, which allows you to specify that all string columns should be frozen unless otherwise specified. This will reduce memory pressure for applications which do not generally mutate string properties of Active Record objects.Sean Griffin, Ryuta Kamizono
-
Deprecate
map!andcollect!onActiveRecord::Result.Ryuta Kamizono
-
Support
relation.andfor intersection as Set theory.david_and_mary = Author.where(id: [david, mary]) mary_and_bob = Author.where(id: [mary, bob]) david_and_mary.merge(mary_and_bob) # => [mary, bob] david_and_mary.and(mary_and_bob) # => [mary] david_and_mary.or(mary_and_bob) # => [david, mary, bob]Ryuta Kamizono
-
Merging conditions on the same column no longer maintain both conditions, and will be consistently replaced by the latter condition in Rails 6.2. To migrate to Rails 6.2's behavior, use
relation.merge(other, rewhere: true).# Rails 6.1 (IN clause is replaced by merger side equality condition) Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob] # Rails 6.1 (both conflict conditions exists, deprecated) Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [] # Rails 6.1 with rewhere to migrate to Rails 6.2's behavior Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob] # Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced) Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob] Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]Ryuta Kamizono
-
Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
Peter Fry
-
Resolve issue with insert_all unique_by option when used with expression index.
When the
:unique_byoption ofActiveRecord::Persistence.insert_allandActiveRecord::Persistence.upsert_allwas used with the name of an expression index, an error was raised. Adding a guard around the formatting behavior for the:unique_bycorrects this.Usage:
create_table :books, id: :integer, force: true do |t| t.column :name, :string t.index "lower(name)", unique: true end Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_nameFixes #39516.
Austen Madden
-
Add basic support for CHECK constraints to database migrations.
Usage:
add_check_constraint :products, "price > 0", name: "price_check" remove_check_constraint :products, name: "price_check"fatkodima
-
Add
ActiveRecord::Base.strict_loading_by_defaultandActiveRecord::Base.strict_loading_by_default=to enable/disable strict_loading mode by default for a model. The configuration's value is inheritable by subclasses, but they can override that value and it will not impact parent class.Usage:
class Developer < ApplicationRecord self.strict_loading_by_default = true has_many :projects end dev = Developer.first dev.projects.first # => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.bogdanvlviv
-
Deprecate passing an Active Record object to
quote/type_castdirectly.Ryuta Kamizono
-
Default engine
ENGINE=InnoDBis no longer dumped to make schema more agnostic.Before:
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t| endAfter:
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t| endRyuta Kamizono
-
Added delegated type as an alternative to single-table inheritance for representing class hierarchies. See ActiveRecord::DelegatedType for the full description.
DHH
-
Deprecate aggregations with group by duplicated fields.
To migrate to Rails 6.2's behavior, use
uniq!(:group)to deduplicate group fields.accounts = Account.group(:firm_id) # duplicated group fields, deprecated. accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit) # => { # [1, 1] => 50, # [2, 2] => 60 # } # use `uniq!(:group)` to deduplicate group fields. accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit) # => { # 1 => 50, # 2 => 60 # }Ryuta Kamizono
-
Deprecate duplicated query annotations.
To migrate to Rails 6.2's behavior, use
uniq!(:annotate)to deduplicate query annotations.accounts = Account.where(id: [1, 2]).annotate("david and mary") # duplicated annotations, deprecated. accounts.merge(accounts.rewhere(id: 3)) # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */ # use `uniq!(:annotate)` to deduplicate annotations. accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate) # SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */Ryuta Kamizono
-
Resolve conflict between counter cache and optimistic locking.
Bump an Active Record instance's lock version after updating its counter cache. This avoids raising an unnecessary
ActiveRecord::StaleObjectErrorupon subsequent transactions by maintaining parity with the corresponding database record'slock_versioncolumn.Fixes #16449.
Aaron Lipman
-
Support merging option
:rewhereto allow mergee side condition to be replaced exactly.david_and_mary = Author.where(id: david.id..mary.id) # both conflict conditions exists david_and_mary.merge(Author.where(id: bob)) # => [] # mergee side condition is replaced by rewhere david_and_mary.merge(Author.rewhere(id: bob)) # => [bob] # mergee side condition is replaced by rewhere option david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]Ryuta Kamizono
-
Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be set to expire and scoped with a purpose. This is particularly useful for things like password reset or email verification, where you want the bearer of the signed id to be able to interact with the underlying record, but usually only within a certain time period.
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset User.find_signed signed_id # => nil, since the purpose does not match travel 16.minutes User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired travel_back User.find_signed signed_id, purpose: :password_reset # => User.first User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignatureDHH
-
Support
ALGORITHM = INSTANTDDL option for index operations on MySQL.Ryuta Kamizono
-
Fix index creation to preserve index comment in bulk change table on MySQL.
Ryuta Kamizono
-
Allow
unscopeto be aware of table name qualified values.It is possible to unscope only the column in the specified table.
posts = Post.joins(:comments).group(:"posts.hidden") posts = posts.where("posts.hidden": false, "comments.hidden": false) posts.count # => { false => 10 } # unscope both hidden columns posts.unscope(where: :hidden).count # => { false => 11, true => 1 } # unscope only comments.hidden column posts.unscope(where: :"comments.hidden").count # => { false => 11 }Ryuta Kamizono, Slava Korolev
-
Fix
rewhereto truly overwrite collided where clause by new where clause.steve = Person.find_by(name: "Steve") david = Author.find_by(name: "David") relation = Essay.where(writer: steve) # Before relation.rewhere(writer: david).to_a # => [] # After relation.rewhere(writer: david).to_a # => [david]Ryuta Kamizono
-
Inspect time attributes with subsec and time zone offset.
p Knot.create => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">akinomaeni, Jonathan Hefner
-
Deprecate passing a column to
type_cast.Ryuta Kamizono
-
Deprecate
in_clause_lengthandallowed_index_name_lengthinDatabaseLimits.Ryuta Kamizono
-
Support bulk insert/upsert on relation to preserve scope values.
Josef Šimánek, Ryuta Kamizono
-
Preserve column comment value on changing column name on MySQL.
Islam Taha
-
Add support for
if_existsoption for removing an index.The
remove_indexmethod can take anif_existsoption. If this is set to true an error won't be raised if the index doesn't exist.Eileen M. Uchitelle
-
Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
Ryuta Kamizono
-
Prevent
build_associationfromtouchinga parent record if the record isn't persisted forhas_oneassociations.Fixes #38219.
Josh Brody
-
Add support for
if_not_existsoption for adding index.The
add_indexmethod respectsif_not_existsoption. If it is set to true index won't be added.Usage:
add_index :users, :account_id, if_not_exists: trueThe
if_not_existsoption passed tocreate_tablealso gets propagated to indexes created within that migration so that if table and its indexes exist then there is no attempt to create them again.Prathamesh Sonpatki
-
Add
ActiveRecord::Base#previously_new_record?to show if a record was new before the last save.Tom Ward
-
Support descending order for
find_each,find_in_batches, andin_batches.Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
Pass
order: :descto yield batches in descending order. The default remainsorder: :asc.Person.find_each(order: :desc) do |person| person.party_all_night! endAlexey Vasiliev
-
Fix
insert_allwith enum values.Fixes #38716.
Joel Blum
-
Add support for
db:rollback:namefor multiple database applications.Multiple database applications will now raise if
db:rollbackis call and recommend using thedb:rollback:[NAME]to rollback migrations.Eileen M. Uchitelle
-
Relation#picknow uses already loaded results instead of making another query.Eugene Kenny
-
Deprecate using
return,breakorthrowto exit a transaction block after writes.Dylan Thacker-Smith
-
Dump the schema or structure of a database when calling
db:migrate:name.In previous versions of Rails,
rails db:migratewould dump the schema of the database. In Rails 6, that holds true (rails db:migratedumps all databases' schemas), butrails db:migrate:namedoes not share that behavior.Going forward, calls to
rails db:migrate:namewill dump the schema (or structure) of the database being migrated.Kyle Thompson
-
Reset the
ActiveRecord::Baseconnection afterrails db:migrate:name.When
rails db:migratehas finished, it ensures theActiveRecord::Baseconnection is reset to its original configuration. Going forward,rails db:migrate:namewill have the same behavior.Kyle Thompson
-
Disallow calling
connected_toon subclasses ofActiveRecord::Base.Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class.
connected_toswitches the context from which we are getting connections, not the connections themselves.Eileen M. Uchitelle, John Crepezzi
-
Add support for horizontal sharding to
connects_toandconnected_to.Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
Usage:
Given the following configuration:
# config/database.yml production: primary: database: my_database primary_shard_one: database: my_database_shard_oneConnect to multiple shards:
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true connects_to shards: { default: { writing: :primary }, shard_one: { writing: :primary_shard_one } }Swap between shards in your controller / model code:
ActiveRecord::Base.connected_to(shard: :shard_one) do # Read from shard one endThe horizontal sharding API also supports read replicas. See guides for more details.
Eileen M. Uchitelle, John Crepezzi
-
Deprecate
spec_namein favor ofnameon database configurations.The accessors for
spec_nameonconfigs_forandDatabaseConfigare deprecated. Please usenameinstead.Deprecated behavior:
db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary") db_config.spec_nameNew behavior:
db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary") db_config.nameEileen M. Uchitelle
-
Add additional database-specific rake tasks for multi-database users.
Previously,
rails db:create,rails db:drop, andrails db:migratewere the only rails tasks that could operate on a single database. For example:rails db:create rails db:create:primary rails db:create:animals rails db:drop rails db:drop:primary rails db:drop:animals rails db:migrate rails db:migrate:primary rails db:migrate:animalsWith these changes,
rails db:schema:dump,rails db:schema:load,rails db:structure:dump,rails db:structure:loadandrails db:test:preparecan additionally operate on a single database. For example:rails db:schema:dump rails db:schema:dump:primary rails db:schema:dump:animals rails db:schema:load rails db:schema:load:primary rails db:schema:load:animals rails db:structure:dump rails db:structure:dump:primary rails db:structure:dump:animals rails db:structure:load rails db:structure:load:primary rails db:structure:load:animals rails db:test:prepare rails db:test:prepare:primary rails db:test:prepare:animalsKyle Thompson
-
Add support for
strict_loadingmode on association declarations.Raise an error if attempting to load a record from an association that has been marked as
strict_loadingunless it was explicitly eager loaded.Usage:
class Developer < ApplicationRecord has_many :projects, strict_loading: true end dev = Developer.first dev.projects.first # => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.Kevin Deisz
-
Add support for
strict_loadingmode to prevent lazy loading of records.Raise an error if a parent record is marked as
strict_loadingand attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.Usage:
dev = Developer.strict_loading.first dev.audit_logs.to_a # => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.Eileen M. Uchitelle, Aaron Patterson
-
Add support for PostgreSQL 11+ partitioned indexes when using
upsert_all.Sebastián Palma
-
Adds support for
if_not_existstoadd_columnandif_existstoremove_column.Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
Example Usage:
class AddColumnTitle < ActiveRecord::Migration[6.1] def change add_column :posts, :title, :string, if_not_exists: true end endclass RemoveColumnTitle < ActiveRecord::Migration[6.1] def change remove_column :posts, :title, if_exists: true end endEileen M. Uchitelle
-
Regexp-escape table name for MS SQL Server.
Add
Regexp.escapeto one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods likepluckandselectfail in certain cases when used with the MS SQL Server adapter.Larry Reid
-
Store advisory locks on their own named connection.
Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
In order to fix this we are storing the advisory lock on a new connection with the connection specification name
AdvisoryLockBase. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.Eileen M. Uchitelle, John Crepezzi
-
Allow schema cache path to be defined in the database configuration file.
For example:
development: adapter: postgresql database: blog_development pool: 5 schema_cache_path: tmp/schema/main.ymlKatrina Owen
-
Deprecate
#remove_connectionin favor of#remove_connection_poolwhen called on the handler.#remove_connectionis deprecated in order to support returning aDatabaseConfigobject instead of aHash. Use#remove_connection_pool,#remove_connectionwill be removed in 6.2.Eileen M. Uchitelle, John Crepezzi
-
Deprecate
#default_hashand it's alias#[]on database configurations.Applications should use
configs_for.#default_hashand#[]will be removed in 6.2.Eileen M. Uchitelle, John Crepezzi
-
Add scale support to
ActiveRecord::Validations::NumericalityValidator.Gannon McGibbon
-
Find orphans by looking for missing relations through chaining
where.missing:Before:
Post.left_joins(:author).where(authors: { id: nil })After:
Post.where.missing(:author)Tom Rossi
-
Ensure
:readingconnections always raise if a write is attempted.Now Rails will raise an
ActiveRecord::ReadOnlyErrorif any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than:reading.Eileen M. Uchitelle
-
Deprecate
"primary"as theconnection_specification_nameforActiveRecord::Base."primary"has been deprecated as theconnection_specification_nameforActiveRecord::Basein favor of using"ActiveRecord::Base". This change affects calls toActiveRecord::Base.connection_handler.retrieve_connectionandActiveRecord::Base.connection_handler.remove_connection. If you're calling these methods with"primary", please switch to"ActiveRecord::Base".Eileen M. Uchitelle, John Crepezzi
-
Add
ActiveRecord::Validations::NumericalityValidatorwith support for casting floats using a database columns' precision value.Gannon McGibbon
-
Enforce fresh ETag header after a collection's contents change by adding ActiveRecord::Relation#cache_key_with_version. This method will be used by ActionController::ConditionalGet to ensure that when collection cache versioning is enabled, requests using ConditionalGet don't return the same ETag header after a collection is modified.
Fixes #38078.
Aaron Lipman
-
Skip test database when running
db:createordb:dropin development withDATABASE_URLset.Brian Buchalter
-
Don't allow mutations on the database configurations hash.
Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the
DatabaseConfigobject directly.Before:
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary") @db_config.configuration_hash.merge!(idle_timeout: "0.02")After:
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary") config = @db_config.configuration_hash.merge(idle_timeout: "0.02") db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)Eileen M. Uchitelle, John Crepezzi
-
Remove
:connection_idfrom thesql.active_recordnotification.Aaron Patterson, Rafael Mendonça França
-
The
:namekey will no longer be returned as part ofDatabaseConfig#configuration_hash. Please useDatabaseConfig#owner_nameinstead.Eileen M. Uchitelle, John Crepezzi
-
ActiveRecord's
belongs_to_required_by_defaultflag can now be set per model.You can now opt-out/opt-in specific models from having their associations required by default.
This change is meant to ease the process of migrating all your models to have their association required.
Edouard Chin
-
The
connection_configmethod has been deprecated, please useconnection_db_configinstead which will return aDatabaseConfigurations::DatabaseConfiginstead of aHash.Eileen M. Uchitelle, John Crepezzi
-
Retain explicit selections on the base model after applying
includesandjoins.Resolves #34889.
Patrick Rebsch
-
The
databasekwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should useconnects_toinstead.Eileen M. Uchitelle, John Crepezzi
-
Allow attributes to be fetched from Arel node groupings.
Jeff Emminger, Gannon McGibbon
-
A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL
options.Joshua Flanagan
-
Calling methods like
establish_connectionwith aHashwhich is invalid (eg: noadapter) will now raise an error the same way as connections defined inconfig/database.yml.John Crepezzi
-
Specifying
implicit_order_columnnow subsorts the records by primary key if available to ensure deterministic results.Paweł Urbanek
-
where(attr => [])now loads an empty result without making a query.John Hawthorn
-
Fixed the performance regression for
primary_keysintroduced MySQL 8.0.Hiroyuki Ishii
-
Add support for
belongs_totohas_manyinversing.Gannon McGibbon
-
Allow length configuration for
has_secure_tokenmethod. The minimum length is set at 24 characters.Before:
has_secure_token :auth_tokenAfter:
has_secure_token :default_token # 24 characters has_secure_token :auth_token, length: 36 # 36 characters has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthErrorBernardo de Araujo
-
Deprecate
DatabaseConfigurations#to_h. These connection hashes are still available viaActiveRecord::Base.configurations.configs_for.Eileen Uchitelle, John Crepezzi
-
Add
DatabaseConfig#configuration_hashto return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. DeprecateDatabaseConfig#configwhich returns a String-keyedHashwith the same values.John Crepezzi, Eileen Uchitelle
-
Allow column names to be passed to
remove_indexpositionally along with other options.Passing other options can be necessary to make
remove_indexcorrectly reversible.Before:
add_index :reports, :report_id # => works add_index :reports, :report_id, unique: true # => works remove_index :reports, :report_id # => works remove_index :reports, :report_id, unique: true # => ArgumentErrorAfter:
remove_index :reports, :report_id, unique: true # => worksEugene Kenny
-
Allow bulk
ALTERstatements to drop and recreate indexes with the same name.Eugene Kenny
-
insert,insert_all,upsert, andupsert_allnow clear the query cache.Eugene Kenny
-
Call
while_preventing_writesdirectly fromconnected_to.In some cases application authors want to use the database switching middleware and make explicit calls with
connected_to. It's possible for an app to turn off writes and not turn them back on by the time we callconnected_to(role: :writing).This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
Eileen M. Uchitelle
-
Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
Kir Shatrov
-
Stop trying to read yaml file fixtures when loading Active Record fixtures.
Gannon McGibbon
-
Deprecate
.reorder(nil)with.first/.first!taking non-deterministic result.To continue taking non-deterministic result, use
.take/.take!instead.Ryuta Kamizono
-
Preserve user supplied joins order as much as possible.
Fixes #36761, #34328, #24281, #12953.
Ryuta Kamizono
-
Allow
matches_regexanddoes_not_match_regexpon the MySQL Arel visitor.James Pearson
-
Allow specifying fixtures to be ignored by setting
ignorein YAML file's '_fixture' section.Tongfei Gao
-
Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
John Crepezzi, Eileen Uchitelle
-
Add a warning for enum elements with 'not_' prefix.
class Foo enum status: [:sent, :not_sent] endEdu Depetris
-
Make currency symbols optional for money column type in PostgreSQL.
Joel Schneider
-
Add support for beginless ranges, introduced in Ruby 2.7.
Josh Goodall
-
Add
database_exists?method to connection adapters to check if a database exists.Guilherme Mansur
-
Loading the schema for a model that has no
table_nameraises aTableNotSpecifiederror.Guilherme Mansur, Eugene Kenny
-
PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
Fixes #36022.
Ryuta Kamizono
-
Make ActiveRecord
ConnectionPool.connectionsmethod thread-safe.Fixes #36465.
Jeff Doering
-
Add support for multiple databases to
rails db:abort_if_pending_migrations.Mark Lee
-
Fix sqlite3 collation parsing when using decimal columns.
Martin R. Schuster
-
Fix invalid schema when primary key column has a comment.
Fixes #29966.
Guilherme Goettems Schneider
-
Fix table comment also being applied to the primary key column.
Guilherme Goettems Schneider
-
Allow generated
create_tablemigrations to include or skip timestamps.Michael Duchemin
Action View
-
SanitizeHelper.sanitized_allowed_attributes and SanitizeHelper.sanitized_allowed_tags call safe_list_sanitizer's class method
Fixes #39586
Taufiq Muhammadi
-
Change form_with to generate non-remote forms by default.
form_withwould generate a remote form by default. This would confuse users because they were forced to handle remote requests.All new 6.1 applications will generate non-remote forms by default. When upgrading a 6.0 application you can enable remote forms by default by setting
config.action_view.form_with_generates_remote_formstotrue.Petrik de Heus
-
Yield translated strings to calls of
ActionView::FormBuilder#buttonwhen a block is given.Sean Doyle
-
Alias
ActionView::Helpers::Tags::Label::LabelBuilder#translationto#to_sso thatform.labelcalls can yield that value to their blocks.Sean Doyle
-
Rename the new
TagHelper#class_namesmethod toTagHelper#token_list, and make the original available as an alias.token_list("foo", "foo bar") # => "foo bar"Sean Doyle
-
ARIA Array and Hash attributes are treated as space separated
DOMTokenListvalues. This is useful when declaring lists of label text identifiers inaria-labelledbyoraria-describedby.tag.input type: 'checkbox', name: 'published', aria: { invalid: @post.errors[:published].any?, labelledby: ['published_context', 'published_label'], describedby: { published_errors: @post.errors[:published].any? } } #=> <input type="checkbox" name="published" aria-invalid="true" aria-labelledby="published_context published_label" aria-describedby="published_errors" >Sean Doyle
-
Remove deprecated
escape_whitelistfromActionView::Template::Handlers::ERB.Rafael Mendonça França
-
Remove deprecated
find_all_anywherefromActionView::Resolver.Rafael Mendonça França
-
Remove deprecated
formatsfromActionView::Template::HTML.Rafael Mendonça França
-
Remove deprecated
formatsfromActionView::Template::RawFile.Rafael Mendonça França
-
Remove deprecated
formatsfromActionView::Template::Text.Rafael Mendonça França
-
Remove deprecated
find_filefromActionView::PathSet.Rafael Mendonça França
-
Remove deprecated
rendered_formatfromActionView::LookupContext.Rafael Mendonça França
-
Remove deprecated
find_filefromActionView::ViewPaths.Rafael Mendonça França
-
Require that
ActionView::Basesubclasses implement#compiled_method_container.Rafael Mendonça França
-
Remove deprecated support to pass an object that is not a
ActionView::LookupContextas the first argument inActionView::Base#initialize.Rafael Mendonça França
-
Remove deprecated
formatargumentActionView::Base#initialize.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#refresh.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#original_encoding.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#variants.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#formats.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#virtual_path=.Rafael Mendonça França
-
Remove deprecated
ActionView::Template#updated_at.Rafael Mendonça França
-
Remove deprecated
updated_atargument required onActionView::Template#initialize.Rafael Mendonça França
-
Make
localsargument required onActionView::Template#initialize.Rafael Mendonça França
-
Remove deprecated
ActionView::Template.finalize_compiled_template_methods.Rafael Mendonça França
-
Remove deprecated
config.action_view.finalize_compiled_template_methodsRafael Mendonça França
-
Remove deprecated support to calling
ActionView::ViewPaths#with_fallbackwith a block.Rafael Mendonça França
-
Remove deprecated support to passing absolute paths to
render template:.Rafael Mendonça França
-
Remove deprecated support to passing relative paths to
render file:.Rafael Mendonça França
-
Remove support to template handlers that don't accept two arguments.
Rafael Mendonça França
-
Remove deprecated pattern argument in
ActionView::Template::PathResolver.Rafael Mendonça França
-
Remove deprecated support to call private methods from object in some view helpers.
Rafael Mendonça França
-
ActionView::Helpers::TranslationHelper#translateaccepts a block, yielding the translated text and the fully resolved translation key:<%= translate(".relative_key") do |translation, resolved_key| %> <span title="<%= resolved_key %>"><%= translation %></span> <% end %>Sean Doyle
-
Ensure cache fragment digests include all relevant template dependencies when fragments are contained in a block passed to the render helper. Remove the virtual_path keyword arguments found in CacheHelper as they no longer possess any function following 1581cab.
Fixes #38984.
Aaron Lipman
-
Deprecate
config.action_view.raise_on_missing_translationsin favor ofconfig.i18n.raise_on_missing_translations.New generalized configuration option now determines whether an error should be raised for missing translations in controllers and views.
fatkodima
-
Instrument layout rendering in
TemplateRenderer#render_with_layoutasrender_layout.action_view, and include (when necessary) the layout's virtual path in notification payloads for collection and partial renders.Zach Kemp
-
ActionView::Base.annotate_rendered_view_with_filenamesannotates HTML output with template file names.Joel Hawksley, Aaron Patterson
-
ActionView::Helpers::TranslationHelper#translatereturns nil when passeddefault: nilwithout a translation matchingI18n#translate.Stefan Wrobel
-
OptimizedFileSystemResolverprefers template details in order of locale, formats, variants, handlers.Iago Pimenta
-
Added
class_nameshelper to create a CSS class value with conditional classes.Joel Hawksley, Aaron Patterson
-
Add support for conditional values to TagBuilder.
Joel Hawksley
-
ActionView::Helpers::FormOptionsHelper#selectshould mark option fornilas selected.@post = Post.new @post.category = nil # Before select("post", "category", none: nil, programming: 1, economics: 2) # => # <select name="post[category]" id="post_category"> # <option value="">none</option> # <option value="1">programming</option> # <option value="2">economics</option> # </select> # After select("post", "category", none: nil, programming: 1, economics: 2) # => # <select name="post[category]" id="post_category"> # <option selected="selected" value="">none</option> # <option value="1">programming</option> # <option value="2">economics</option> # </select>bogdanvlviv
-
Log lines for partial renders and started template renders are now emitted at the
DEBUGlevel instead ofINFO.Completed template renders are still logged at the
INFOlevel.DHH
-
ActionView::Helpers::SanitizeHelper: support rails-html-sanitizer 1.1.0.
Juanito Fatas
-
Added
phone_tohelper method to create a link from mobile numbers.Pietro Moro
-
annotated_source_code returns an empty array so TemplateErrors without a template in the backtrace are surfaced properly by DebugExceptions.
Guilherme Mansur, Kasper Timm Hansen
-
Add autoload for SyntaxErrorInTemplate so syntax errors are correctly raised by DebugExceptions.
Guilherme Mansur, Gannon McGibbon
-
RenderingHelpersupports rendering objects thatrespond_to?:render_in.Joel Hawksley, Natasha Umer, Aaron Patterson, Shawn Allen, Emily Plummer, Diana Mounter, John Hawthorn, Nathan Herald, Zaid Zawaideh, Zach Ahn
-
Fix
select_tagso that it doesn't changeoptionswheninclude_blankis present.Younes SERRAJ
Action Pack
-
Support for the HTTP header
Feature-Policyhas been revised to reflect its rename toPermissions-Policy.Rails.application.config.permissions_policy do |p| p.camera :none p.gyroscope :none p.microphone :none p.usb :none p.fullscreen :self p.payment :self, "https://secure-example.com" endJulien Grillot
-
Allow
ActionDispatch::HostAuthorizationto exclude specific requests.Host Authorization checks can be skipped for specific requests. This allows for health check requests to be permitted for requests with missing or non-matching host headers.
Chris Bisnett
-
Add
config.action_dispatch.request_id_headerto allow changing the name of the unique X-Request-Id headerArlston Fernandes
-
Deprecate
config.action_dispatch.return_only_media_type_on_content_type.Rafael Mendonça França
-
Change
ActionDispatch::Response#content_typeto return the full Content-Type header.Rafael Mendonça França
-
Remove deprecated
ActionDispatch::Http::ParameterFilter.Rafael Mendonça França
-
Added support for exclusive no-store Cache-Control header.
If
no-storeis set on Cache-Control header it is exclusive (all other cache directives are dropped).Chris Kruger
-
Catch invalid UTF-8 parameters for POST requests and respond with BadRequest.
Additionally, perform
#set_binary_encodinginActionDispatch::Http::Request#GETandActionDispatch::Http::Request#POSTprior to validating encoding.Adrianna Chang
-
Allow
assert_recognizesrouting assertions to work on mounted root routes.Gannon McGibbon
-
Change default redirection status code for non-GET/HEAD requests to 308 Permanent Redirect for
ActionDispatch::SSL.Alan Tan, Oz Ben-David
-
Fix
follow_redirect!to follow redirection with same HTTP verb when following a 308 redirection.Alan Tan
-
When multiple domains are specified for a cookie, a domain will now be chosen only if it is equal to or is a superdomain of the request host.
Jonathan Hefner
-
ActionDispatch::Statichandles precompiled Brotli (.br) files.Adds to existing support for precompiled gzip (.gz) files. Brotli files are preferred due to much better compression.
When the browser requests /some.js with
Accept-Encoding: br, we check for public/some.js.br and serve that file, if present, withContent-Encoding: brandVary: Accept-Encodingheaders.Ryan Edward Hall, Jeremy Daer
-
Add raise_on_missing_translations support for controllers.
This configuration determines whether an error should be raised for missing translations. It can be enabled through
config.i18n.raise_on_missing_translations. Note that described configuration also affects raising error for missing translations in views.fatkodima
-
Added
compactandcompact!toActionController::Parameters.Eugene Kenny
-
Calling
each_pairoreach_valueon anActionController::Parameterswithout passing a block now returns an enumerator.Eugene Kenny
-
fixture_file_uploadnow uses path relative tofile_fixture_pathPreviously the path had to be relative to
fixture_path. You can change your existing code as follow:# Before fixture_file_upload('files/dog.png') # After fixture_file_upload('dog.png')Edouard Chin
-
Remove deprecated
force_sslat the controller level.Rafael Mendonça França
-
The +helper+ class method for controllers loads helper modules specified as strings/symbols with
String#constantizeinstead ofrequire_dependency.Remember that support for strings/symbols is only a convenient API. You can always pass a module object:
helper UtilsHelperwhich is recommended because it is simple and direct. When a string/symbol is received,
helperjust manipulates and inflects the argument to obtain that same module object.Xavier Noria, Jean Boussier
-
Correctly identify the entire localhost IPv4 range as trusted proxy.
Nick Soracco
-
url_forwill now use "https://" as the default protocol whenRails.application.config.force_sslis set to true.Jonathan Hefner
-
Accept and default to base64_urlsafe CSRF tokens.
Base64 strict-encoded CSRF tokens are not inherently websafe, which makes them difficult to deal with. For example, the common practice of sending the CSRF token to a browser in a client-readable cookie does not work properly out of the box: the value has to be url-encoded and decoded to survive transport.
Now, we generate Base64 urlsafe-encoded CSRF tokens, which are inherently safe to transport. Validation accepts both urlsafe tokens, and strict-encoded tokens for backwards compatibility.
Scott Blum
-
Support rolling deploys for cookie serialization/encryption changes.
In a distributed configuration like rolling update, users may observe both old and new instances during deployment. Users may be served by a new instance and then by an old instance.
That means when the server changes
cookies_serializerfrom:marshalto:hybridor the server changesuse_authenticated_cookie_encryptionfromfalsetotrue, users may lose their sessions if they access the server during deployment.We added fallbacks to downgrade the cookie format when necessary during deployment, ensuring compatibility on both old and new instances.
Masaki Hara
-
ActionDispatch::Request.remote_iphas ip address even when all sites are trusted.Before, if all
X-Forwarded-Forsites were trusted, theremote_ipwould default to127.0.0.1. Now, the furthest proxy site is used. e.g.: It now gives an ip address when using curl from the load balancer.Keenan Brock
-
Fix possible information leak / session hijacking vulnerability.
The
ActionDispatch::Session::MemcacheStoreis still vulnerable given it requires the gem dalli to be updated as well.CVE-2019-16782.
-
Include child session assertion count in ActionDispatch::IntegrationTest.
IntegrationTest#open_sessionusesdupto create the new session, which meant it had its own copy of@assertions. This prevented the assertions from being correctly counted and reported.Child sessions now have their
attr_accessoroverridden to delegate to the root session.Fixes #32142.
Sam Bostock
-
Add SameSite protection to every written cookie.
Enabling
SameSitecookie protection is an addition to CSRF protection, where cookies won't be sent by browsers in cross-site POST requests when set to:lax.:strictdisables cookies being sent in cross-site GET or POST requests.Passing
:nonedisables this protection and is the same as previous versions albeit a; SameSite=Noneis appended to the cookie.See upgrade instructions in config/initializers/new_framework_defaults_6_1.rb.
More info here
NB: Technically already possible as Rack supports SameSite protection, this is to ensure it's applied to all cookies
Cédric Fabianski
-
Bring back the feature that allows loading external route files from the router.
This feature existed back in 2012 but got reverted with the incentive that https://github.com/rails/routing_concerns was a better approach. Turned out that this wasn't fully the case and loading external route files from the router can be helpful for applications with a really large set of routes. Without this feature, application needs to implement routes reloading themselves and it's not straightforward.
# config/routes.rb Rails.application.routes.draw do draw(:admin) end # config/routes/admin.rb get :foo, to: 'foo#bar'Yehuda Katz, Edouard Chin
-
Fix system test driver option initialization for non-headless browsers.
glaszig
-
redirect_to.action_controllernotifications now include theActionDispatch::Requestin their payloads as:request.Austin Story
-
respond_to#anyno longer returns a response's Content-Type based on the request format but based on the block given.Example:
def my_action respond_to do |format| format.any { render(json: { foo: 'bar' }) } end end get('my_action.csv')The previous behaviour was to respond with a
text/csvContent-Type which is inaccurate since a JSON response is being rendered.Now it correctly returns a
application/jsonContent-Type.Edouard Chin
-
Replaces (back)slashes in failure screenshot image paths with dashes.
If a failed test case contained a slash or a backslash, a screenshot would be created in a nested directory, causing issues with
tmp:clear.Damir Zekic
-
Add
params.member?to mimic Hash behavior.Younes Serraj
-
process_action.action_controllernotifications now include the following in their payloads::request- theActionDispatch::Request:response- theActionDispatch::Response
George Claghorn
-
Updated
ActionDispatch::Request.remote_ipsetter to clear set the instanceremote_iptonilbefore setting the header that the value is derived from.Fixes #37383.
Norm Provost
-
ActionController::Base.log_atallows setting a different log level per request.# Use the debug level if a particular cookie is set. class ApplicationController < ActionController::Base log_at :debug, if: -> { cookies[:debug] } endGeorge Claghorn
-
Allow system test screen shots to be taken more than once in a test by prefixing the file name with an incrementing counter.
Add an environment variable
RAILS_SYSTEM_TESTING_SCREENSHOT_HTMLto enable saving of HTML during a screenshot in addition to the image. This uses the same image name, with the extension replaced with.htmlTom Fakes
-
Add
Vary: Acceptheader when usingAcceptheader for response.For some requests like
/users/1, Rails uses requests'Acceptheader to determine what to return. And if we don't addVaryin the response header, browsers might accidentally cache different types of content, which would cause issues: e.g. javascript got displayed instead of html content. This PR fixes these issues by addingVary: Acceptin these types of requests. For more detailed problem description, please read:https://github.com/rails/rails/pull/36213
Fixes #25842.
Stan Lo
-
Fix IntegrationTest
follow_redirect!to follow redirection using the same HTTP verb when following a 307 redirection.Edouard Chin
-
System tests require Capybara 3.26 or newer.
George Claghorn
-
Reduced log noise handling ActionController::RoutingErrors.
Alberto Fernández-Capel
-
Add DSL for configuring HTTP Feature Policy.
This new DSL provides a way to configure an HTTP Feature Policy at a global or per-controller level. Full details of HTTP Feature Policy specification and guidelines can be found at MDN:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
Example global policy:
Rails.application.config.feature_policy do |f| f.camera :none f.gyroscope :none f.microphone :none f.usb :none f.fullscreen :self f.payment :self, "https://secure.example.com" endExample controller level policy:
class PagesController < ApplicationController feature_policy do |p| p.geolocation "https://example.com" end endJacob Bednarz
-
Add the ability to set the CSP nonce only to the specified directives.
Fixes #35137.
Yuji Yaginuma
-
Keep part when scope option has value.
When a route was defined within an optional scope, if that route didn't take parameters the scope was lost when using path helpers. This commit ensures scope is kept both when the route takes parameters or when it doesn't.
Fixes #33219.
Alberto Almagro
-
Added
deep_transform_keysanddeep_transform_keys!methods to ActionController::Parameters.Gustavo Gutierrez
-
Calling
ActionController::Parameters#transform_keys/!without a block now returns an enumerator for the parameters instead of the underlying hash.Eugene Kenny
-
Fix strong parameters blocks all attributes even when only some keys are invalid (non-numerical). It should only block invalid key's values instead.
Stan Lo
Active Job
-
Recover nano precision when serializing
Time,TimeWithZoneandDateTimeobjects.Alan Tan
-
Deprecate
config.active_job.return_false_on_aborted_enqueue.Rafael Mendonça França
-
Return
falsewhen enqueuing a job is aborted.Rafael Mendonça França
-
While using
perform_enqueued_jobstest helper enqueued jobs must be stored for the later check withassert_enqueued_with.Dmitry Polushkin
-
ActiveJob::TestCase#perform_enqueued_jobswithout a block removes performed jobs from the queue.That way the helper can be called multiple times and not perform a job invocation multiple times.
def test_jobs HelloJob.perform_later("rafael") perform_enqueued_jobs # only runs with "rafael" HelloJob.perform_later("david") perform_enqueued_jobs # only runs with "david" endÉtienne Barrié
-
ActiveJob::TestCase#perform_enqueued_jobswill no longer perform retries:When calling
perform_enqueued_jobswithout a block, the adapter will now perform jobs that are already in the queue. Jobs that will end up in the queue afterwards won't be performed.This change only affects
perform_enqueued_jobswhen no block is given.Edouard Chin
-
Add queue name support to Que adapter.
Brad Nauta, Wojciech Wnętrzak
-
Don't run
after_enqueueandafter_performcallbacks if the callback chain is halted.class MyJob < ApplicationJob before_enqueue { throw(:abort) } after_enqueue { # won't enter here anymore } endafter_enqueueandafter_performcallbacks will no longer run if the callback chain is halted. This behaviour is a breaking change and won't take effect until Rails 6.2. To enable this behaviour in your app right now, you can add in your app's configuration fileconfig.active_job.skip_after_callbacks_if_terminated = true.Edouard Chin
-
Fix enqueuing and performing incorrect logging message.
Jobs will no longer always log "Enqueued MyJob" or "Performed MyJob" when they actually didn't get enqueued/performed.
class MyJob < ApplicationJob before_enqueue { throw(:abort) } end MyJob.perform_later # Will no longer log "Enqueued MyJob" since job wasn't even enqueued through adapter.A new message will be logged in case a job couldn't be enqueued, either because the callback chain was halted or because an exception happened during enqueuing. (i.e. Redis is down when you try to enqueue your job)
Edouard Chin
-
Add an option to disable logging of the job arguments when enqueuing and executing the job.
class SensitiveJob < ApplicationJob self.log_arguments = false def perform(my_sensitive_argument) end endWhen dealing with sensitive arguments as password and tokens it is now possible to configure the job to not put the sensitive argument in the logs.
Rafael Mendonça França
-
Changes in
queue_name_prefixof a job no longer affects all other jobs.Fixes #37084.
Lucas Mansur
-
Allow
ClassandModuleinstances to be serialized.Kevin Deisz
-
Log potential matches in
assert_enqueued_withandassert_performed_with.Gareth du Plooy
-
Add
atargument to theperform_enqueued_jobstest helper.John Crepezzi, Eileen Uchitelle
-
assert_enqueued_withandassert_performed_withcan now test jobs with relative delay.Vlado Cingel
-
Add jitter to
ActiveJob::Exceptions.retry_on.ActiveJob::Exceptions.retry_onnow uses a random amount of jitter in order to prevent the thundering herd effect. Defaults to 15% (represented as 0.15) but overridable via the:jitteroption when usingretry_on. Jitter is applied when anInteger,ActiveSupport::Durationor:exponentially_longer, is passed to thewaitargument inretry_on.retry_on(MyError, wait: :exponentially_longer, jitter: 0.30)Anthony Ross
Action Mailer
-
Change default queue name of the deliver (
:mailers) job to be the job adapter's default (:default).Rafael Mendonça França
-
Remove deprecated
ActionMailer::Base.receivein favor of Action Mailbox.Rafael Mendonça França
-
Fix ActionMailer assertions don't work for parameterized mail with legacy delivery job.
bogdanvlviv
-
Added
email_address_with_nameto properly escape addresses with names.Sunny Ripert
Action Cable
-
ActionCable::Connection::Basenow allows intercepting unhandled exceptions withrescue_frombefore they are logged, which is useful for error reporting tools and other integrations.Justin Talbott
-
Add
ActionCable::Channel#stream_or_reject_forto stream if record is present, otherwise reject the connectionAtul Bhosale
-
Add
ActionCable::Channel#stop_stream_fromand#stop_stream_forto unsubscribe from a specific stream.Zhang Kang
-
Add PostgreSQL subscription connection identificator.
Now you can distinguish Action Cable PostgreSQL subscription connections among others. Also, you can set custom
idincable.ymlconfiguration.SELECT application_name FROM pg_stat_activity; /* application_name ------------------------ psql ActionCable-PID-42 (2 rows) */Sergey Ponomarev
-
Subscription confirmations and rejections are now logged at the
DEBUGlevel instead ofINFO.DHH
Active Storage
-
Change default queue name of the analysis (
:active_storage_analysis) and purge (:active_storage_purge) jobs to be the job adapter's default (:default).Rafael Mendonça França
-
Implement
strict_loadingon ActiveStorage associations.David Angulo
-
Remove deprecated support to pass
:combine_optionsoperations toActiveStorage::Transformers::ImageProcessing.Rafael Mendonça França
-
Remove deprecated
ActiveStorage::Transformers::MiniMagickTransformer.Rafael Mendonça França
-
Remove deprecated
config.active_storage.queue.Rafael Mendonça França
-
Remove deprecated
ActiveStorage::Downloading.Rafael Mendonça França
-
Add per-environment configuration support
Pietro Moro
-
The Poppler PDF previewer renders a preview image using the original document's crop box rather than its media box, hiding print margins. This matches the behavior of the MuPDF previewer.
Vincent Robert
-
Touch parent model when an attachment is purged.
Víctor Pérez Rodríguez
-
Files can now be served by proxying them from the underlying storage service instead of redirecting to a signed service URL. Use the
rails_storage_proxy_pathand_urlhelpers to proxy an attached file:<%= image_tag rails_storage_proxy_path(@user.avatar) %>To proxy by default, set
config.active_storage.resolve_model_to_route:# Proxy attached files instead. config.active_storage.resolve_model_to_route = :rails_storage_proxy<%= image_tag @user.avatar %>To redirect to a signed service URL when the default file serving strategy is set to proxying, use the
rails_storage_redirect_pathand_urlhelpers:<%= image_tag rails_storage_redirect_path(@user.avatar) %>Jonathan Fleckenstein
-
Add
config.active_storage.web_image_content_typesto allow applications to add content types (likeimage/webp) in which variants can be processed, instead of letting those images be converted to the fallback PNG format.Jeroen van Haperen
-
Add support for creating variants of
WebPimages out of the box.Dino Maric
-
Only enqueue analysis jobs for blobs with non-null analyzer classes.
Gannon McGibbon
-
Previews are created on the same service as the original blob.
Peter Zhu
-
Remove unused
dispositionandcontent_typequery parameters forDiskService.Peter Zhu
-
Use
DiskControllerfor both public and private files.DiskControlleris able to handle multiple services by adding aservice_namefield in the generated URL inDiskService.Peter Zhu
-
Variants are tracked in the database to avoid existence checks in the storage service.
George Claghorn
-
Deprecate
service_urlmethods in favour ofurl.Deprecate
Variant#service_urlandPreview#service_urlto instead use#urlmethod to be consistent withBlob.Peter Zhu
-
Permanent URLs for public storage blobs.
Services can be configured in
config/storage.ymlwith a new keypublic: true | falseto indicate whether a service holds public blobs or private blobs. Public services will always return a permanent URL.Deprecates
Blob#service_urlin favor ofBlob#url.Peter Zhu
-
Make services aware of configuration names.
Gannon McGibbon
-
The
Content-Typeheader is set on image variants when they're uploaded to third-party storage services.Kyle Ribordy
-
Allow storage services to be configured per attachment.
class User < ActiveRecord::Base has_one_attached :avatar, service: :s3 end class Gallery < ActiveRecord::Base has_many_attached :photos, service: :s3 endDmitry Tsepelev
-
You can optionally provide a custom blob key when attaching a new file:
user.avatar.attach key: "avatars/#{user.id}.jpg", io: io, content_type: "image/jpeg", filename: "avatar.jpg"Active Storage will store the blob's data on the configured service at the provided key.
George Claghorn
-
Replace
Blob.create_after_upload!withBlob.create_and_upload!and deprecate the former.create_after_upload!has been removed since it could lead to data corruption by uploading to a key on the storage service which happened to be already taken. Creating the record would then correctly raise a database uniqueness exception but the stored object would already have overwritten another.create_and_upload!swaps the order of operations so that the key gets reserved up-front or the uniqueness error gets raised, before the upload to a key takes place.Julik Tarkhanov
-
Set content disposition in direct upload using
filenameanddispositionparameters toActiveStorage::Service#headers_for_direct_upload.Peter Zhu
-
Allow record to be optionally passed to blob finders to make sharding easier.
Gannon McGibbon
-
Switch from
azure-storagegem toazure-storage-blobgem for Azure service.Peter Zhu
-
Add
config.active_storage.draw_routesto disable Active Storage routes.Gannon McGibbon
-
Image analysis is skipped if ImageMagick returns an error.
ActiveStorage::Analyzer::ImageAnalyzer#metadatawould previously raise aMiniMagick::Error, which caused persistentActiveStorage::AnalyzeJobfailures. It now logs the error and returns{}, resulting in no metadata being added to the offending image blob.George Claghorn
-
Method calls on singular attachments return
nilwhen no file is attached.Previously, assuming the following User model,
user.avatar.filenamewould raise aModule::DelegationErrorif no avatar was attached:class User < ApplicationRecord has_one_attached :avatar endThey now return
nil.Matthew Tanous
-
The mirror service supports direct uploads.
New files are directly uploaded to the primary service. When a directly-uploaded file is attached to a record, a background job is enqueued to copy it to each secondary service.
Configure the queue used to process mirroring jobs by setting
config.active_storage.queues.mirror. The default is:active_storage_mirror.George Claghorn
-
The S3 service now permits uploading files larger than 5 gigabytes.
When uploading a file greater than 100 megabytes in size, the service transparently switches to multipart uploads using a part size computed from the file's total size and S3's part count limit.
No application changes are necessary to take advantage of this feature. You can customize the default 100 MB multipart upload threshold in your S3 service's configuration:
production: service: s3 access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> region: us-east-1 bucket: my-bucket upload: multipart_threshold: <%= 250.megabytes %>George Claghorn
Action Mailbox
-
Change default queue name of the incineration (
:action_mailbox_incineration) and routing (:action_mailbox_routing) jobs to be the job adapter's default (:default).Rafael Mendonça França
-
Sendgrid ingress now passes through the envelope recipient as
X-Original-To.Mark Haussmann
-
Update Mandrill inbound email route to respond appropriately to HEAD requests for URL health checks from Mandrill.
Bill Cromie
-
Add way to deliver emails via source instead of filling out a form through the conductor interface.
DHH
-
Mailgun ingress now passes through the envelope recipient as
X-Original-To.Rikki Pitt
-
Deprecate
Rails.application.credentials.action_mailbox.api_keyandMAILGUN_INGRESS_API_KEYin favor ofRails.application.credentials.action_mailbox.signing_keyandMAILGUN_INGRESS_SIGNING_KEY.Matthijs Vos
-
Allow easier creation of multi-part emails from the
create_inbound_email_from_mailandreceive_inbound_email_from_mailtest helpers.Michael Herold
-
Fix Bcc header not being included with emails from
create_inbound_email_fromtest helpers.jduff
-
Add
ApplicationMailbox.mailbox_forto expose mailbox routing.James Dabbs
Action Text
-
Declare
ActionText::FixtureSet.attachmentto generate an<action-text-attachment sgid="..."></action-text-attachment>element with a validsgidattribute.hello_world_review_content: record: hello_world (Review) name: content body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>Sean Doyle
-
Locate
fill_in_rich_text_areaby<label>textIn addition to searching for
<trix-editor>elements with the appropriatearia-labelattribute, also support locating elements that match the corresponding<label>element's text.Sean Doyle
-
Be able to add a default value to
rich_text_area.form.rich_text_area :content, value: "<h1>Hello world</h1>" #=> <input type="hidden" name="message[content]" id="message_content_trix_input_message_1" value="<h1>Hello world</h1>">Paulo Ancheta
-
Add method to confirm rich text content existence by adding
?after rich text attribute.message = Message.create!(body: "<h1>Funny times!</h1>") message.body? #=> trueKyohei Toyoda
-
The
fill_in_rich_text_areasystem test helper locates a Trix editor and fills it in with the given HTML.# <trix-editor id="message_content" ...></trix-editor> fill_in_rich_text_area "message_content", with: "Hello <em>world!</em>" # <trix-editor placeholder="Your message here" ...></trix-editor> fill_in_rich_text_area "Your message here", with: "Hello <em>world!</em>" # <trix-editor aria-label="Message content" ...></trix-editor> fill_in_rich_text_area "Message content", with: "Hello <em>world!</em>" # <input id="trix_input_1" name="message[content]" type="hidden"> # <trix-editor input="trix_input_1"></trix-editor> fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>"George Claghorn
Railties
-
Added
Railtie#serverhook called when Rails starts a server. This is useful in case your application or a library needs to run another process next to the Rails server. This is quite common in development for instance to run the Webpack or the React server.It can be used like this:
class MyRailtie < Rails::Railtie server do WebpackServer.run end endEdouard Chin
-
Remove deprecated
rake dev:cachetasks.Rafael Mendonça França
-
Remove deprecated
rake routestasks.Rafael Mendonça França
-
Remove deprecated
rake initializerstasks.Rafael Mendonça França
-
Remove deprecated support for using the
HOSTenvironment variable to specify the server IP.Rafael Mendonça França
-
Remove deprecated
serverargument from the rails server command.Rafael Mendonça França
-
Remove deprecated
SOURCE_ANNOTATION_DIRECTORIESenvironment variable support fromrails notes.Rafael Mendonça França
-
Remove deprecated
connectionoption in therails dbconsolecommand.Rafael Mendonça França
-
Remove depreated
rake notestasks.Rafael Mendonça França
-
Return a 405 Method Not Allowed response when a request uses an unknown HTTP method.
Fixes #38998.
Loren Norman
-
Make railsrc file location xdg-specification compliant
rails newwill now look for the defaultrailsrcfile at$XDG_CONFIG_HOME/rails/railsrc(or~/.config/rails/railsrcifXDG_CONFIG_HOMEis not set). If this file does not exist,rails newwill fall back to~/.railsrc.The fallback behaviour means this does not cause any breaking changes.
Nick Wolf
-
Change the default logging level from :debug to :info to avoid inadvertent exposure of personally identifiable information (PII) in production environments.
Eric M. Payne
-
Automatically generate abstract class when using multiple databases.
When generating a scaffold for a multiple database application, Rails will now automatically generate the abstract class for the database when the database argument is passed. This abstract class will include the connection information for the writing configuration and any models generated for that database will automatically inherit from the abstract class.
Usage:
$ bin/rails generate scaffold Pet name:string --database=animalsWill create an abstract class for the animals connection.
class AnimalsRecord < ApplicationRecord self.abstract_class = true connects_to database: { writing: :animals } endAnd generate a
Petmodel that inherits from the newAnimalsRecord:class Pet < AnimalsRecord endIf you already have an abstract class and it follows a different pattern than Rails defaults, you can pass a parent class with the database argument.
$ bin/rails generate scaffold Pet name:string --database=animals --parent=SecondaryBaseThis will ensure the model inherits from the
SecondaryBaseparent instead ofAnimalsRecordclass Pet < SecondaryBase endEileen M. Uchitelle, John Crepezzi
-
Accept params from url to prepopulate the Inbound Emails form in Rails conductor.
Chris Oliver
-
Create a new rails app using a minimal stack.
rails new cool_app --minimalAll the following are excluded from your minimal stack:
- action_cable
- action_mailbox
- action_mailer
- action_text
- active_job
- active_storage
- bootsnap
- jbuilder
- spring
- system_tests
- turbolinks
- webpack
Haroon Ahmed, DHH
-
Add default ENV variable option with BACKTRACE to turn off backtrace cleaning when debugging framework code in the generated config/initializers/backtrace_silencers.rb.
BACKTRACE=1 ./bin/rails runner "MyClass.perform"DHH
-
The autoloading guide for Zeitwerk mode documents how to autoload classes during application boot in a safe way.
Haroon Ahmed, Xavier Noria
-
The
classicautoloader starts its deprecation cycle.New Rails projects are strongly discouraged from using
classic, and we recommend that existing projects running onclassicswitch tozeitwerkmode when upgrading. Please check the Upgrading Ruby on Rails guide for tips.Xavier Noria
-
Adds
rails test:allfor running all tests in the test directory.This runs all test files in the test directory, including system tests.
Niklas Häusele
-
Add
config.generators.after_generatefor processing to generated files.Register a callback that will get called right after generators has finished.
Yuji Yaginuma
-
Make test file patterns configurable via Environment variables
This makes test file patterns configurable via two environment variables:
DEFAULT_TEST, to configure files to test, andDEFAULT_TEST_EXCLUDE, to configure files to exclude from testing.These values were hardcoded before, which made it difficult to add new categories of tests that should not be executed by default (e.g: smoke tests).
Jorge Manrubia
-
No longer include
rake rdoctask when generating plugins.To generate docs, use the
rdoc libcommand instead.Jonathan Hefner
-
Allow relative paths with trailing slashes to be passed to
rails test.Eugene Kenny
-
Add
rack-mini-profilergem to the defaultGemfile.rack-mini-profilerdisplays performance information such as SQL time and flame graphs. It's enabled by default in development environment, but can be enabled in production as well. See the gem README for information on how to enable it in production.Osama Sayegh
-
rails statswill now count TypeScript files toward JavaScript stats.Joshua Cody
-
Run
git initwhen generating plugins.Opt out with
--skip-git.OKURA Masafumi
-
Add benchmark generator.
Introduce benchmark generator to benchmark Rails applications.
rails generate benchmark opt_compareThis creates a benchmark file that uses
benchmark-ips. By default, two code blocks can be benchmarked using thebeforeandafterreports.You can run the generated benchmark file using:
ruby script/benchmarks/opt_compare.rbKevin Jalbert, Gannon McGibbon
-
Cache compiled view templates when running tests by default.
When generating a new app without
--skip-spring, caching classes is disabled inenvironments/test.rb. This implicitly disables caching view templates too. This change will enable view template caching by adding this to the generatedenvironments/test.rb:config.action_view.cache_template_loading = trueJorge Manrubia
-
Introduce middleware move operations.
With this change, you no longer need to delete and reinsert a middleware to move it from one place to another in the stack:
config.middleware.move_before ActionDispatch::Flash, Magical::UnicornsThis will move the
Magical::Unicornsmiddleware beforeActionDispatch::Flash. You can also move it after with:config.middleware.move_after ActionDispatch::Flash, Magical::UnicornsGenadi Samokovarov
-
Generators that inherit from NamedBase respect
--forceoption.Josh Brody
-
Allow configuration of eager_load behaviour for rake environment:
config.rake_eager_loadDefaults to
falseas per previous behaviour.Thierry Joyal
-
Ensure Rails migration generator respects system-wide primary key config.
When rails is configured to use a specific primary key type:
config.generators do |g| g.orm :active_record, primary_key_type: :uuid endPreviously:
$ bin/rails g migration add_location_to_users location:referencesThe references line in the migration would not have
type: :uuid. This change causes the type to be applied appropriately.Louis-Michel Couture, Dermot Haughey
-
Deprecate
Rails::DBConsole#config.Rails::DBConsole#configis deprecated without replacement. UseRails::DBConsole.db_config.configuration_hashinstead.Eileen M. Uchitelle, John Crepezzi
-
Rails.application.config_formerges shared configuration deeply.# config/example.yml shared: foo: bar: baz: 1 development: foo: bar: qux: 2# Previously Rails.application.config_for(:example)[:foo][:bar] #=> { qux: 2 } # Now Rails.application.config_for(:example)[:foo][:bar] #=> { baz: 1, qux: 2 }Yuhei Kiriyama
-
Remove access to values in nested hashes returned by
Rails.application.config_forvia String keys.# config/example.yml development: options: key: valueRails.application.config_for(:example).optionsThis used to return a Hash on which you could access values with String keys. This was deprecated in 6.0, and now doesn't work anymore.
Étienne Barrié
-
Configuration files for environments (
config/environments/*.rb) are now able to modifyautoload_paths,autoload_once_paths, andeager_load_paths.As a consequence, applications cannot autoload within those files. Before, they technically could, but changes in autoloaded classes or modules had no effect anyway in the configuration because reloading does not reboot.
Ways to use application code in these files:
-
Define early in the boot process a class that is not reloadable, from which the application takes configuration values that get passed to the framework.
# In config/application.rb, for example. require "#{Rails.root}/lib/my_app/config" # In config/environments/development.rb, for example. config.foo = MyApp::Config.foo -
If the class has to be reloadable, then wrap the configuration code in a
to_prepareblock:config.to_prepare do config.foo = MyModel.foo endThat assigns the latest
MyModel.footoconfig.foowhen the application boots, and each time there is a reload. But whether that has an effect or not depends on the configuration point, since it is not uncommon for engines to read the application configuration during initialization and set their own state from them. That process happens only on boot, not on reloads, and if that is howconfig.fooworked, resetting it would have no effect in the state of the engine.
Allen Hsu & Xavier Noria
-
-
Support using environment variable to set pidfile.
Ben Thorner