Ruby on Rails: Treat deprecation warnings as errors or otherwise find deprecated code?

匿名 (未验证) 提交于 2019-12-03 03:05:02

问题:

I recently upgraded from Rails 2 to Rails 3, and I'm trying to root out all the code I might have that is deprecated. The way I'm doing this is just surfing around a copy of my site running on a development machine, and peering at the output from the console for warnings.

Is there a way to cause Rails to treat deprecation warnings as errors or otherwise find deprecated code more efficiently?

回答1:

You can customise the behaviour of deprecated calls by setting ActiveSupport::Deprecation.behavior. This should be set to a Proc that accepts a message and a callstack e.g. you could do:

ActiveSupport::Deprecation.behavior = Proc.new { |message, callstack|   raise message + "\n" + callstack.join("\n  ") } 

If you have automated tests for your app these are invaluable when upgrading the version of Rails being used.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!