微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 升级到Rails 4时,批量分配失败

deprecated_mass_assignment_security.rb:17:in `attr_accessible': `attr_accessible` is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add `protected_attributes` to your Gemfile to use old one. (RuntimeError)

我尝试了消息所说的内容,将gem“strong_parameters”添加到我的Gemfile中.

但是当我做rails时,我得到了上面的错误.

更新

我试过了:

config.active_record.whitelist_attributes = true

在confgi / application.rb中,也是假的,但实际上我不明白那个选项.

解决方法

在你的Gemfile中你会注意到gem’en protected_attributes’已经被删除了.
删除哈希.
运行捆绑安装.

但是由于protected_attributes已被弃用并且将来可能会消失,请使用上面帖子中提到的strong_parameters.

有关strong_parameters的更多信息,请参阅此link.

原文地址:https://www.jb51.cc/ruby/264951.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐