config.active_record.whitelist_attributes = 在 Rails 4.2 应用程序中为假

config.active_record.whitelist_attributes = false in Rails 4.2 App

我们的 rails 4.2 应用程序由多个 rails 引擎组成,有或没有 gem 'protected_attributes'。我们发现,在应用程序的 application.rb 中,它必须是:

config.active_record.whitelist_attributes = false

否则任何create/update都无法进行,因为params无法赋值给实例变量。我们的问题是,如果rails app中没有gem protected_attributes,我们还需要application.rb中的config.active_record.whitelist_attributes = false吗?这是 Rails 3.x 还是带有 gem protected_attributes 的应用?

我查看了我拥有的几个 rails 4 个应用程序,其中 none 个包含该配置,当我搜索配置名称时,protected_attributes gem 出现在结果中,所以我认为您可以假设它仅与 protected_attributes gem 有关并且您不需要它

本文来自protected_attributes gem.

whitelist_attributes = truecauses attr_accessible(nil) 默认为所有模型添加意味着你不能为任何模型批量分配任何属性,除非它有自己的 attr_accessibleattr_protected

这可以在旧版本的README.md

中看到

从版本 1.1.2 开始,现在是 depreciated and does nothing other than log a depreciation warning

因此,如果您使用的是 Rails 4+ 应用程序并且没有 protected_attributes gem,那么您可以安全地删除它