Rails 5 中的弃用警告

Joh*_*ohn 7 ruby-on-rails ruby-on-rails-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: 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)
Run Code Online (Sandbox Code Playgroud)

当我检查第 5 行时config/environment.rb,有以下代码:

Rails.application.initialize!
Run Code Online (Sandbox Code Playgroud)

当我在我的仓库中搜索after_action,after_filter或 时alias_method_chain,没有找到。我该怎么做才能摆脱这些警告?

Sea*_*ler 0

我最近遇到了同样的错误。创建新的 Rails 5 应用程序大约 2 分钟后出现此错误。当我遇到同样的错误时,我什至刚刚开始以下Chartkick 教程

操作顺序

  1. Rails g 模型 访问国家/地区:字符串visited_at:日期时间load_time:十进制
  2. 耙数据库:迁移
  3. 繁荣!收到同样的错误&它不会让我继续制作我的模式。

错误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!

错误消息提到了config/application.rb第 7 行的问题,如下所示:

require_relative 'boot'
require 'rails/all'

**Bundler.require(*Rails.groups)**
module Chartkick
    class Application < Rails::Application
    end
end
Run Code Online (Sandbox Code Playgroud)

第 7 行:Bundler.require(*Rails.groups) *星号用于区分第 7 行。

我没有发现第 7 行有什么真正的问题。


尝试用以下命令解决它:

  • Bundle exec rake db:migrate [遇到相同的错误]

  • 捆绑更新

最后,解决了导致我出现错误的部分问题 - 使用以下代码:

bin/rake db:create

rake db:migrate

我仍然有相同的错误消息,但我现在可以使用和访问我的数据库。错误显然仍然存在,但它不再阻碍我的进步。我还应该注意到,我的新 Rails 应用程序是使用 postgresql 作为默认数据库构建的。

rails new chartkick --database=postgresql
Run Code Online (Sandbox Code Playgroud)

不确定这对您的情况是否有帮助,但它可能会帮助其他人调试此问题。