Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DEPRECATION WARNING: alias_method_chain is deprecated

I upgraded the project to Rails 5. When I run rspec I get a warning

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. 
From module, you can access the original method using super. 
(called from <top (required)> at /home/alex/projects/myproject/config/application.rb:13)

The failing line in application.rb is:

Bundler.require(*Rails.groups)

How do I find out what is causing this deprecation warning and how to get rid of the error?

like image 997
Alex Shmatko Avatar asked Oct 21 '16 09:10

Alex Shmatko


4 Answers

Install (unless already installed) ack and run in the terminal:

ack alias_method_chain /Users/username/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.1/gems/

It will indicate all places where alias_method_chain is used (files and code lines).

99% chance it is used in some of your gems.

See my answer for a list of things you can do about it.

like image 96
Andrey Deineko Avatar answered Oct 11 '22 03:10

Andrey Deineko


In OSX, you can use:

grep -Ir alias_method_chain `bundle show rails`/..

And that will list all of the gems that use alias_method_chain

like image 26
BananaNeil Avatar answered Oct 11 '22 03:10

BananaNeil


If the Gemfile is too large I would recommend to use the_silver_searcher to search for deprecated alias_method_chain because it is faster

ag alias_method_chain /path/to/gemset

I have gepgems bash helper function to not type /path/to/gemset every time

grepgems alias_method_chain

To use it add the following function to your .bash_profile (or somewhere else in the dotfiles you like)

function grepgems() {
  ag $1 $GEM_HOME"/gems"
}
like image 29
Hirurg103 Avatar answered Oct 11 '22 02:10

Hirurg103


Solution for docker :

docker exec -it [CONTAINER_NAME] /bin/bash

apt-get install silversearcher-ag

ag alias_method_chain $GEM_HOME"/gems"

like image 36
pcmanprogrammeur Avatar answered Oct 11 '22 03:10

pcmanprogrammeur