消除 Rails 3 中的弃用警告
谁能告诉我如何消除 Rails 3 中的弃用警告?
我遇到过一些会引发误报的情况。即在 haml 和来自dynamic_form插件的f.error_messages中使用-for循环。
谢谢
Can anyone tell me how to silence deprecation warinings in Rails 3?
I have a few situations where it is throwing false positives. Namely using - for loops in haml and f.error_messages from the dynamic_form plugin.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使所有弃用警告静音,您可以执行以下操作:
这可以放置在初始化程序中或特定环境的环境文件中(例如,仅在生产中静音。)
或者对于代码的特定部分,将其包含在块中:
这适用于 Rails 3 和 Rails 3。 4.
To silence all deprecation warnings you can do:
This could be placed in an initializer or in the environment file for a specific environment (e.g. to silence only in production for example.)
Or for a specific section of code, enclose it in a block:
This works for both Rails 3 & 4.
接受的答案对 Rails 3.2.12 不起作用。将其放置在环境/生产.rb 或初始化程序中仍然会输出警告。在初始化应用程序之前,我必须将其放入 config/environment.rb 文件中:
The accepted answer didn't work for me with Rails 3.2.12. Placing it in either the environments/production.rb or an initializer still outputted the warnings. I had to put it in my config/environment.rb file before the application was initialized:
Ryan Daigle 写了一篇关于此的文章,其中他还展示了如何拦截弃用警告并对其执行其他操作,例如将其发送到日志文件:
http://ryandaigle.com/articles/2006/12/4/how-to-turn-弃用警告-off-in-rails
Ryan Daigle wrote an article about this, in which he also showed how you can intercept the deprecation warning and do something else with it, like send it to a log file:
http://ryandaigle.com/articles/2006/12/4/how-to-turn-deprecation-warnings-off-in-rails