ruby-on-rails - 方法 sort_by 已弃用 - 可能的解决方案?
问题描述
我目前的 Rails 项目发出警告 -
DEPRECATION WARNING: Method sort_by is deprecated and will be removed in Rails 5.1, as ActionController::Parameters no longer inherits from hash.
我已经搜索了这个警告以及潜在的修复,但根本找不到任何关于它的东西。我想知道这里是否有人有任何建议、修复或替换sort_by
?如果这是一个简单的解决方案,我很抱歉,因为我仍在学习 rails。
感谢您花时间阅读和/或回答。
Rails -v 5.0.7.2 | Ruby -v 2.6.4
解决方案
在 Rails 5 中,ActionController::Parameters 将不再继承自 HashWithIndifferentAccess。
Inheriting from `HashWithIndifferentAccess` allowed users to call any
enumerable methods on `Parameters` object, resulting in a risk of losing the
`permitted?` status or even getting back a pure `Hash` object instead of
a `Parameters` object with proper sanitization.
如果您需要将 ActionController::Parameters 转换为真正的哈希,那么它支持to_h
方法。此外,ActionController::Parameters 将继续拥有诸如 fetch、slice、slice!、except、except!、extract!、delete 等方法。您可以在此处详细了解它们。
推荐阅读
- python - 如何按升序浏览目录中的文件
- javascript - 如何修复车把中的前端 javascript 从服务器捕获未定义的值?
- r - 将列读取为范围以比较值
- node.js - MetaMask Web3 以太坊未定义
- c - 无法更新程序中的项目配置变量
- tensorflow - TensorFlow Keras SavedModel 空变量文件夹
- unit-testing - 如何模拟 IdentityServerDbContext 以添加 ApplicationUser
- c++ - 2 的补码二进制预期输出
- assembly - 我试图理解“rep scasb byte [edi]”指令
- elasticsearch - ELK docker image 观察到数组中的对象没有得到很好的支持错误