如何在 Rails 控制台中隐藏数据库输出? [英] How can you hide database output in Rails console?
本文介绍了如何在 Rails 控制台中隐藏数据库输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在较新版本的 Rails 中,我猜从 3 起,数据库查询会输出到控制台.这在大多数情况下很有用,但是当您不想看到它时,如何隐藏它?
In newer version of Rails, I'm guessing from 3 up, database queries are output to the console. This is useful most of the time, but how can you hide it when you do not want to see it?
推荐答案
更好的方法是在控制台中输入:
A better way of doing this is by typing this into the console:
ActiveRecord::Base.logger.level = 1
因为它可以防止尝试使用指向设置为 nil 的记录器的指针时出现问题(来源:在控制台中禁用 Rails SQL 日志)
as it prevents problems trying use a pointer to a logger that is set to nil (source: Disable Rails SQL logging in console)
重新开启
ActiveRecord::Base.logger.level = 0
这篇关于如何在 Rails 控制台中隐藏数据库输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文