Reputation: 6612
Every time I execute my tests, I get these deprecation warnings:
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 /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
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 /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from <top (required)> at /Users/johnvanarkelen/Documents/Web development/rails/test-eagle/config/environment.rb:5)
When I check line 5 of config/environment.rb
, there is this code:
Rails.application.initialize!
When I search my repo for after_action
, after_filter
or alias_method_chain
, it is not found. What can I do to get rid of these warnings?
Upvotes: 7
Views: 3771
Reputation: 29241
I ran into alias_method_chain is deprecated ... from <top (required)> at /path/to/your/environment.rb
in a recent rails 5 upgrade. This typically points to usage in a gem required during the initialize!
call on your Rails application or a Bundler.require
if you are manually requiring your dependencies (which I happened to be).
It's probably better expressed as:
One of the random Gems you depend on did something I didn't like while Rails was initializing. Have fun finding it!
These are the loose steps I followed to sort out these unknown errors:
bundle show rails
or $GEM_PATH
to figure out where the gems for your bundle currently live (do note that this may be different for gems from different sources, e.g. git dependencies are stored differently than those from rubygems)grep
, ripgrip
ag
) to search for the deprecated method name e.g. rg "alias_method_chain" <gem path>
In my case, the deprecation warning for alias_method_chain
was in an outdated version of Kaminari. I updated my Gemfile to allow for a more recent version and then ran bundle update kaminari
to sort it.
Ignoring these warnings is a very bad idea; it's easy to let little things like this slip into your application if they have no immediate impact. That leads to normalizing the behavior of ignoring warnings or errors; that means more bugs and inconsistency in your application and a guaranteed bad time when you try to upgrade to a version of rails that removes the deprecated behavior. If you or your team establishes a standard of finding and fixing these errors immediately it's easy to spot and resolve real problems when they come up. Your future self will thank you :)
Upvotes: 4
Reputation: 131
I ran into this same error recently. Got this error about 2 minutes into creating a new Rails 5 application. I had barely even started the following chartkick tutorial when I got same error.
Order of Operation
The Error:
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 richOnRails/chartkick/config/application.rb:7)
rake aborted!
The error message mentioned trouble in line 7 of config/application.rb depicted below:
require_relative 'boot'
require 'rails/all'
**Bundler.require(*Rails.groups)**
module Chartkick
class Application < Rails::Application
end
end
Line 7: Bundler.require(*Rails.groups) *asterisks used to distinguish line 7.
I didn't see anything truly wrong with line 7.
Tried to solve it with following commands:
bundle exec rake db:migrate [got same error]
bundle update
Finally, solved part of the issue giving me the error - with the following code:
bin/rake db:create
rake db:migrate
I still have the same error message but I'm now able to use & access my database. The error apparently is still present but it's no longer hindering my progress. I should also note that my new rails app was built with postgresql as default database.
rails new chartkick --database=postgresql
Not sure if this is helpful in your case but it might help others in debugging this problem.
Upvotes: 0