9

私は頻繁に Rails コンソールに移動する必要がありrails cます。次に、モデルのレコードをループするステートメントを実行します。情報を出力する必要がありますが、すべての 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出力を抑制する簡単な方法は?

4

1 に答える 1

17

これをコンソールに入力するか、コンソールの構成ファイルに入れます。

ActiveRecord::Base.logger = nil
于 2013-05-29T21:36:35.083 に答える