Question

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 
Was it helpful?

Solution

In general you can replace the returning line with this call to tap:

[].tap do |full_messages|

However your method looks like it's equivalent to values.compact, so you can just replace your code with that.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top