使用cancancan和rails的弃用警告

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

我在使用rspec-rails进行测试时总会得到这个:

DEPRECATION WARNING: Initialization autoloaded the constant Ability.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Ability, for example,
the expected changes won't be reflected in that stale Class object.

This autoloaded constant has been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.
 (called from <top (required)> at MyApp/config/environment.rb:5)

如何解决此弃用警告?

ruby-on-rails rspec cancancan
1个回答
0
投票

在相关环境文件中添加以下行,例如production.rb,staging.rb

 ActiveSupport::Deprecation.silenced = true

https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html

© www.soinside.com 2019 - 2024. All rights reserved.