有人能告诉我如何消除Rails 3中的弃用警告吗?
我的一些情况会引起误报,即在haml中使用“-”循环和使用dynamic_form插件中的f.error_messages。
谢谢。
有人能告诉我如何消除Rails 3中的弃用警告吗?
我的一些情况会引起误报,即在haml中使用“-”循环和使用dynamic_form插件中的f.error_messages。
谢谢。
要消除所有警告信息,您可以执行以下操作:
ActiveSupport::Deprecation.silenced = true
这可以放在初始化器或特定环境的环境文件中(例如,仅在生产环境中消除噪音)。
或者针对特定代码段,将其包含在块中:
ActiveSupport::Deprecation.silence do
# no warnings for any use of deprecated methods here
end
这适用于Rails 3和4。
对于Rails 3.2.12,已接受的答案对我没有起作用。将其放置在environments/production.rb或初始化程序中仍会输出警告。我不得不将其放在config/environment.rb文件中,在应用程序初始化之前:
# Load the rails application
require File.expand_path('../application', __FILE__)
::ActiveSupport::Deprecation.silenced = true if Rails.env.production?
# Initialize the rails application
Notices::Application.initialize!
Ryan Daigle写了一篇关于这个的文章,在其中他还展示了如何拦截弃用警告并采取其他操作,比如将其发送到日志文件中:
ActiveSupport::Deprecation.behavior = Proc.new { |msg, stack| MyLogger.warn(msg) }
http://ryandaigle.com/articles/2006/12/4/how-to-turn-deprecation-warnings-off-in-rails