弃用警告:Object#returning 已被弃用,取而代之的是 Object#tap
如何更改以下方法以使用 tap
来停止警告,例如
DEPRECATION WARNING: Object#returning 已被弃用,转而使用 Object#tap。 (从 /Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17 处的 full_messages 调用) :
ActiveModel::Errors.class_eval do
# Remove complicated logic
def full_messages
returning full_messages = [] do
self.each_key do |attr|
self[attr].each do |msg|
full_messages << msg if msg
end
end
end
end
end
How to change the following method to use tap
to stop the warnings like
DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from full_messages at /Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17)
:
ActiveModel::Errors.class_eval do
# Remove complicated logic
def full_messages
returning full_messages = [] do
self.each_key do |attr|
self[attr].each do |msg|
full_messages << msg if msg
end
end
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,您可以将
returning
行替换为对tap
的调用:但是您的方法看起来与
values.compact
等效,因此您可以只需用它替换您的代码即可。In general you can replace the
returning
line with this call totap
:However your method looks like it's equivalent to
values.compact
, so you can just replace your code with that.如果升级旧的 Rails 2 应用程序,可能会出现此警告消息。自 Rails 版本 2.3.9< /a> Kernel#returning 函数已被替换为 Ruby 1.8.7 原生的 Object#tap。不幸的是,这个错误通常是由较旧的插件和 gem 引起的。对我来说,它帮助将 haml 版本从 2.0.x 更新到 3.0.21,将 will_paginate 版本从 2.2.x 更新到 2.3.15。
This warning message can occur if you upgrade old Rails 2 applications. Since the Rails Version 2.3.9 the Kernel#returning function has been replaced with Object#tap which is native to Ruby 1.8.7. Unfortunately this error often is caused by older plugins and gems. For me it helped to update the haml version from 2.0.x to 3.0.21, and the will_paginate version from 2.2.x to 2.3.15.