【问题标题】:config.active_record.whitelist_attributes = false in Rails 4.2 AppRails 4.2 应用程序中的 config.active_record.whitelist_attributes = false
【发布时间】:2015-05-10 20:02:29
【问题描述】:

我们的 rails 4.2 应用程序包含几个带有或不带 gem 'protected_attributes' 的 rails 引擎。我们发现,在应用程序的application.rb 中,它必须是:

config.active_record.whitelist_attributes = false

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

【问题讨论】:

    标签: ruby-on-rails-3 ruby-on-rails-4 strong-parameters


    【解决方案1】:

    我查看了我拥有的几个 rails 4 应用程序,它们都没有包含该配置,当我用谷歌搜索配置名称时,protected_attributes gem 出现在结果中,所以我想你可以假设它只是相关的到protected_attributes gem 并且你不需要它

    【讨论】:

      【解决方案2】:

      这来自protected_attributes gem。

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

      这可以在旧版本的README.md中看到

      从 1.1.2 版开始,它现在是 depreciated,除了记录 depreciation warning 之外什么也不做

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-06-12
        • 1970-01-01
        • 1970-01-01
        • 2016-04-24
        • 2019-08-25
        • 2017-05-27
        • 1970-01-01
        相关资源
        最近更新 更多