如何在 Rails 应用程序中将legacy_connection_handling 设置为 false?

问题描述 投票:0回答:1

请设定 您的申请中的

legacy_connection_handling
false

有人可以帮忙解决这个问题吗?它告诉我将其设置为 false,但我是编码新手,我不知道如何去做。

可以

 % bundle exec rspec
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter.

Read more about how to migrate at: https://guides.rubyonrails.org/active_record_multiple_databases.html#migrate-to-the-new-connection-handling
 (called from <top (required)> at /Users/a/rails-activerecord-models-and-rails-readme/config/environment.rb:5)
No examples found.


Finished in 0.00019 seconds (files took 0.94409 seconds to load)
0 examples, 0 failures

这是我的环境.rb 文件中的内容

# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

我去了它告诉我的网站,我想我的文件可能有问题(它已经生成为这样)它有 Rails.application.initialize!但我不知道如何将其设置为 false。

model-view-controller activerecord
1个回答
2
投票

根据您使用的 Rails 版本,可以通过将更改添加到

application.rb
或用于生产、登台、测试等的单个环境文件来完成。(可能看起来像
config/environments/production.rb
等)

来自错误消息中链接的文档:https://guides.rubyonrails.org/v7.0/active_record_multiple_databases.html#migrate-to-the-new-connection-handling

您可以打开

application.rb
文件并添加以下内容来解决问题:

config.active_record.legacy_connection_handling = false
© www.soinside.com 2019 - 2024. All rights reserved.