gpt4 book ai didi

ruby-on-rails - 在Rails控制台中抑制SQL输出的简单方法?

转载 作者:行者123 更新时间:2023-12-04 03:40:36 29 4
gpt4 key购买 nike

我经常需要使用rails c在Rails控制台上运行。然后,我运行一些语句,该语句遍历模型的记录。我需要输出信息,但是所有的SQL代码也会变得乱七八糟。喜欢:

Students.all.each {|s| puts s.inspect unless s.attendance};nil

我把那个 nil放在最后,这样我就不会收到所有学生的丑陋转储。这是输出:
  Student Load (4.3ms)  SELECT "students".* FROM "students"
Attendance Load (3.6ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2694 LIMIT 1
Attendance Load (2.7ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2695 LIMIT 1
Attendance Load (4.9ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2689 LIMIT 1
#<Student id: 3, attendance_id: 2689, teacher_id: 6, began_at: "2013-05-21 19:16:37", finished_at: "2013-05-21 20:34:33", created_at: "2013-05-21 19:16:37", updated_at: "2013-05-21 20:34:33">
Attendance Load (2.0ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2692 LIMIT 1
#<Student id: 26, attendance_id: 2713, teacher_id: 6, began_at: "2013-05-21 22:44:25", finished_at: "2013-05-21 22:44:42", created_at: "2013-05-21 22:44:25", updated_at: "2013-05-21 22:44:42">
Attendance Load (1.6ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2714 LIMIT 1
#<Student id: 27, attendance_id: 2714, teacher_id: 3, began_at: "2013-05-21 22:45:06", finished_at: "2013-05-21 22:45:27", created_at: "2013-05-21 22:45:06", updated_at: "2013-05-21 22:45:27">
Attendance Load (4.0ms) SELECT "attendances".* FROM "attendances" WHERE "attendances"."id" = 2712 LIMIT 1

在这里,实际上还算不错,但是有时仍然很难看清我想要的东西。抑制SQL输出的简便方法?

最佳答案

在控制台中输入此内容,或将其放入控制台的配置文件中:

ActiveRecord::Base.logger = nil

关于ruby-on-rails - 在Rails控制台中抑制SQL输出的简单方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16824169/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com