자주 레일 콘솔에 rails c
으로 가야합니다. 그런 다음 모델 레코드를 반복하는 문장을 실행합니다. 나는 정보를 출력 할 필요가 있지만, 모든 SQL 코드는 전체적으로 뒤죽박죽이다. 마찬가지로 :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 출력을 억제하기 위해?
참조 http://stackoverflow.com/questions/7759321/disable-rails-3-1-sql-logging – eugen