Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alias_method_chain is deprecated - Rails 5 upgrade

I'm updating my rails app and I need to refactor a method that is using alias_method_chain because it is deprecated. The message says to use module#prepend as recommended by Rails 5. Here is the helper that I'm trying to refactor:

 module ActiveSupport
  module NumberHelper
    def number_to_delimited_with_unicode_infinity(number, options = {})
      result = number_to_delimited_without_unicode_infinity(number, options)
      result.sub(/^Infinity$/, "∞")
    end
    alias_method_chain :number_to_delimited, :unicode_infinity
  end
end

If anyone know how I can refactor with super or some other way let me know thank you!

like image 478
Bitwise Avatar asked Nov 25 '25 08:11

Bitwise


1 Answers

This works for me. I don't know why they used alias_method_chain to begin with but this gets rid of the deprecation warning with the same functionality.

module ActiveSupport
  module NumberHelper
    def number_to_delimited(number, options = {})
      number.to_s.sub(/^Infinity$/, "∞")
    end
  end
end
like image 90
Bitwise Avatar answered Nov 28 '25 02:11

Bitwise



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!