【问题标题】:Deprecation Warning About Mass Assignment Rails 4.0关于批量分配 Rails 4.0 的弃用警告
【发布时间】:2016-11-11 13:50:16
【问题描述】:

我正在将应用升级到 4.0 并使用 ruby​​-2.2.5。我遇到了几个弃用警告,这些警告在我运行 >> bundle exec rake 时出现。

警告之一:

DEPRECATION WARNING: Model based mass assignment security has been extracted out of Rails into a gem. 
Please use the new recommended protection model for params or add `protected_attributes` to your Gemfile to use the old one.

To disable this message remove the `whitelist_attributes` option from your `config/application.rb` file 
and any `mass_assignment_sanitizer` options from your `config/environments/*.rb` files.

See http://guides.rubyonrails.org/security.html#mass-assignment for more information.

我了解这是怎么回事,并且我已经检查了所有模型以查找和删除“attr_accessible”。我已经检查了所有控制器并添加了一个用于 strong_params 的方法,我在我的“创建”和“更新”操作中调用了该方法。我们没有使用“whitelist_attributes”或任何“mass_assignment_sanitizer”选项。而且,我的所有规格测试都通过了。

我的问题是,此警告是否只是标准输出,还是来自 rails 看到的东西我不是?想法?

非常感谢

【问题讨论】:

  • 我认为在其中一个环境文件中有一个设置,或者 application.rb 如果你仍然有它,也许这就是 rails 抱怨的原因
  • # Raise exception on mass assignment protection for Active Record 模型 >> config.active_record.mass_assignment_sanitizer = :strict
  • >> config.active_record.mass_assignment_sanitizer = :strict,在环境/test.rb 和 development.rb 中。将这些注释掉会删除弃用警告。谢谢j-dexx。我没想到会去看那里——很明显。

标签: ruby-on-rails ruby ruby-on-rails-4


【解决方案1】:

尝试在您的 Gemfile 中添加 gem 'protected_attributes', '~>1.1.3',有人说在 Rails 4 上不需要 gem,但它修复了弃用,我不确定是否是最好的解决方案:https://github.com/rails/protected_attributes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    • 2014-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多