Suppress particular warning in Ruby

ぐ巨炮叔叔 提交于 2019-12-05 05:54:26

If there's a specific section of code that produces the warnings, you could try mixing in the Kernel module from ActiveSupport and wrap it with a silence_warnings block (example pulled straight from the RDoc):

silence_warnings do
  value = do_something_that_causes_warning # no warning voiced
end

noisy_call # warning voiced

Is it absolutely necessary to suppress it? It's not like you're compiling something and have to sift through a ton of warnings all at once...

Edit: If you use read_attribute(:id), then you should avoid the waring. Thanks Jeremy!

I'm not a Rails developer, but isn't there a method that allows you to say "I want the database field id, not the id method of the object"?

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