去年的这个时候,我报道了Ruby on Rails 5.2 Deprecations,得到了很多赞赏的反馈。随着Ruby on Rails的下一次重大更新的到来,我想我应该做一篇新的文章,并使之成为一种传统。
注意:Ruby on Rails 6.0将需要Ruby 2.5.0。因此,如果你因为某种原因而停留在旧版本的Ruby上,你可能想考虑暂缓将你的应用程序更新到6.0。
我可能会在以后的测试版和候选版到来时更新这篇文章。
ActionMailer
弃用ActionMailer::Base.receive ,改用Action Mailbox。
增加MailDeliveryJob ,用于发送常规和参数化邮件。废弃使用DeliveryJob 和Parameterized::DeliveryJob 。
动作包
删除废弃的fragment_cache_key 帮助器,改用combined_fragment_cache_key 。
移除ActionDispatch::TestResponse 中被废弃的方法。
#success?,missing? 和error? 在 Rails 5.2 中被废弃,转而使用#successful?,not_found? 和server_error? 。
弃用ActionDispatch::Http::ParameterFilter ,改用ActiveSupport::ParameterFilter 。
控制器级别的force_ssl 已经被废弃,而改用config.force_ssl 。
ActionView
删除废弃的image_alt 帮助器。
废弃从视图助手中调用私有模型方法。
例如,在options_from_collection_for_select 和collection_select 这样的方法中,可以从使用的对象中调用私有方法。
ActiveRecord
从事务对象中删除废弃的#set_state 。
从数据库适配器中删除废弃的#supports_statement_cache? 。
从数据库适配器中删除废弃的#insert_fixtures 。
移除废弃的ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type? 。
废弃的config.activerecord.sqlite3.represent_boolean_as_integer 。
移除废弃的ActiveRecord::Migrator.migrations_path= 。
移除废弃的expand_hash_conditions_for_aggregates 。
摒弃将migrations_paths 传递给connection.assume_migrated_upto_version 的做法。
弃用ActiveRecord::Result#to_hash ,改用ActiveRecord::Result#to_a 。
废弃column_name_length,table_name_length,columns_per_table,indexes_per_table,columns_per_multicolumn_index,sql_query_length, 和joins_per_query 在DatabaseLimits 的方法。
废弃update_attributes/! ,改用update/! 。
ActiveStorage
用两个选项取代config.active_storage.queue ,这两个选项分别指示分析和清除工作应该使用哪个队列。
config.active_storage.queues.analysisconfig.active_storage.queues.purge
config.active_storage.queue 当它被设置时,优先于新选项,但它已被废弃,并将在Rails 6.1中被移除。
增加ActiveStorage::Blob#open ,它可以下载一个 blob 到磁盘上的 tempfile,并产生 tempfile。弃用ActiveStorage::Downloading 。
对Active Storage变体使用ImageProcessinggem,并废除了MiniMagick后端。
这意味着,如果原始图像被旋转,变体现在会自动调整方向。此外,除了现有的ImageMagick操作外,变体现在可以使用:resize_to_fit 、:resize_to_fill ,以及其他ImageProcessing宏。现在推荐使用这些宏,而不是原始的:resize ,因为它们在调整大小后还能锐化缩略图。
ImageProcessing gem还带有一个在libvips上实现的后端,它是ImageMagick的替代品,在大多数情况下,无论是速度还是内存使用,都比ImageMagick的性能好很多。在Active Storage中,现在可以通过将Rails.application.config.active_storage.variant_processor 改为:vips 来切换到libvips后端。
ActiveSupport
移除已废弃的Module#reachable? 方法。
从Inflections 移除已废弃的#acronym_regex 方法。
弃用ActiveSupport::Multibyte::Unicode#pack_graphemes(array) 和ActiveSuppport::Multibyte::Unicode#unpack_graphemes(string) ,改用array.flatten.pack("U*") 和string.scan(/\X/).map(&:codepoints) 。
弃用ActiveSupport::Multibyte::Chars.consumes? ,改用String#is_utf8? 。
弃用ActiveSupport::Multibyte::Unicode#normalize 和ActiveSuppport::Multibyte::Chars#normalize ,改用 。String#unicode_normalize
弃用ActiveSupport::Multibyte::Unicode#downcase/upcase/swapcase ,改用String#downcase/upcase/swapcase 。
摒弃使用LoggerSilence ,改用 。ActiveSupport::LoggerSilence
摒弃在String#first 和String#last 中使用负数限制。
允许Range#=== 和Range#cover? 在Range上。
Range#cover? 现在可以像 和 一样接受一个范围参数。 在Ruby 2.6上正确工作。 被移到一个新的文件中,有这两个方法Range#include? Range#=== Range#=== Range#include?
要求 active_support/core_ext/range/include_range 的做法现在已被弃用。 使用require "active_support/core_ext/range/compare_range" 代替。