大家好,我是 Greg,为各位带来 Rails 的最新更新。
确保并发映射使用线程安全此请求修改了缓存不命中的处理方式。使其线程安全,并确保它在执行过程中不会被覆盖。
自动加载 ActiveModel::ValidationError此请求为 Active Model 中缺失的 ValidationError 添加了自动加载调用。
对最新记录副本执行 before_committed! 回调在此更改之前,仅使用相同记录的早期副本(不同的对象 ID,但指向数据库中的相同记录)来执行回调,但它没有 touch_later 信息。
确保即使在 Active Record 不存在的情况下也设置 file_fixture_path使用 –skip-active-record 生成应用时,file_fixture 助手会失败,因为只有在定义 ActiveRecord::Base 时才会定义 file_fixture_path。此请求即使在 Active Record 不存在的情况下也会加载测试助手。
将 X-Forwarded-To 地址添加到接收者此请求增强了 Mail::Message#recipients,以包括将电子邮件转发到的地址。
为 FormBuilder#fields 和 FormBuilder#fields_for 允许散列式模型此请求更改了 ActionView::Helpers::FormBuilder#fields_for 解释参数的方式。在决定 record_object 参数实际上是 fields_options 参数之前,Rails 现在会检查此 fields_options 是否尚未明确提供。
添加构建持久性方法此请求向 ActiveRecord::Persistence 添加了一个构建方法,它构建一个对象(或多个对象)并返回构建的对象或对象。以下是几个使用示例
# Build a single new object
User.build(first_name: 'Jamie')
# Build an Array of new objects
User.build([{ first_name: 'Jamie' }, { first_name: 'Jeremy' }])
# Build a single object and pass it into a block to set other attributes.
User.build(first_name: 'Jamie') do |u|
u.is_admin = false
end
允许按属性设置 YAML 序列化选项此请求添加了根据每个属性(以及当前应用程序范围设置)来设置 YAML 序列化选项的功能。
为选择帮助程序添加对选择组的 HTML 属性的支持通过此更改,当使用分组/嵌套集合时,select 的选项可以将 HTML 属性作为子数组的最后一个元素包含在内
<%= form.select :foo, [["North America", [["United States","US"],["Canada","CA"]], { disabled: "disabled" }]] %>
# => <select><optgroup label="North America" disabled="disabled"><option value="US">United States</option><option value="CA">Canada</option></optgroup></select>
允许重置单一关联has_one 和 belongs_to 关联现在在所有者模型上定义了一个 reset_association 方法(其中“association”是关联的名称)。此方法将卸载缓存的关联记录(如果有),并导致下次访问从数据库中查询它。请求说明中有一个使用示例。
Avoid validating belongs_to association if it has not changed With this change, Rails avoids validating belongs_to association if it has not changed. Previously, when updating a record, Active Record performed an extra query to check for the presence of belongs_to associations (if the presence is configured to be mandatory), even if that attribute hasn’t changed. Currently, only belongs_to-related columns are checked for presence. It is possible to have orphaned records with this approach. To avoid this problem, you need to use a foreign key. This behavior can be controlled by configuration
config.active_record.belongs_to_required_validates_foreign_key = false
and will be disabled by default with load_defaults 7.1
.
Restore Action Cable Redis pub/sub listener on connection failure The Redis pub/sub adapter now automatically reconnects when Redis connection is lost.
Add option to disable all methods that ActiveRecord.enum generates This pull request adds the instance_methods, option to the enum definition. When it is set to false, Active Record will not generate the instance methods it does by default.
This is a long issue and even being this long, it doesn’t cover everything from past week. You can see the whole list of changes here. We had 24 contributors to Rails this past week!
Happy Thanksgiving if you celebrate it and see you next week!
订阅以通过邮件获取这些更新。