5

Ich muss häufig auf der Rails-Konsole mit rails c gehen. Dann führe ich eine Anweisung aus, die Datensätze eines Modells durchläuft. Ich muss Informationen ausgeben, aber der gesamte SQL-Code wird auch überall verstreut. Wie:Einfache Möglichkeit, SQL-Ausgabe in der Rails-Konsole zu unterdrücken?

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

habe ich, dass nil am Ende, damit ich nicht eine hässliche Dump aller Schüler bekommen. Dies ist die Ausgabe:

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 

Hier ist es eigentlich gar nicht so schlecht, aber es ist immer noch manchmal schwer zu sehen, was ich will. Einfache Möglichkeit, die SQL-Ausgabe zu unterdrücken?

+2

Siehe http://stackoverflow.com/questions/7759321/disable-rails-3-1-sql-logging – eugen

Antwort

10

Geben Sie diese in der Konsole, oder legen Sie sie in der Konfigurationsdatei der Konsole:

ActiveRecord::Base.logger = nil 
+0

"console's config file": Kannst du mir sagen wo ist diese Datei? Ich würde gerne meine Konsole ein wenig anpassen – MrYoshiji

+0

@MrYoshiji, für den Fall ist es '~/.pryrc'. Nicht sicher für irb. – Mori

Verwandte Themen