5

मुझे अक्सर rails c के साथ रेल कंसोल पर जाने की आवश्यकता है। फिर मैं कुछ बयान चलाता हूं जो एक मॉडल के रिकॉर्ड के माध्यम से loops। मुझे जानकारी आउटपुट करने की ज़रूरत है, लेकिन सभी एसक्यूएल कोड भी पूरे हो जाते हैं। जैसा:रेल कंसोल में एसक्यूएल आउटपुट को दबाने का आसान तरीका?

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 

यहाँ यह वास्तव में इतना बुरा नहीं है, लेकिन यह अभी भी जो मैं चाहता देखने के लिए कभी कभी मुश्किल है। एसक्यूएल आउटपुट को दबाने का आसान तरीका?

+2

देखें http://stackoverflow.com/questions/7759321/disable-rails-3-1-sql-logging – eugen

उत्तर

10

कंसोल में इस दर्ज करें, या कंसोल के कॉन्फ़िग फ़ाइल में रख:

ActiveRecord::Base.logger = nil 
+0

"कंसोल की कॉन्फ़िगरेशन फ़ाइल": क्या आप मुझे बता सकते हैं कि यह फ़ाइल कहां है? मैं अपने कंसोल को थोड़ा सा – MrYoshiji

+0

@MrYoshiji कस्टमाइज़ करना चाहता हूं, क्योंकि यह '~/.pryrc' है। Irb के लिए निश्चित नहीं है। – Mori

संबंधित मुद्दे