0
作爲此後續從post:我試圖記錄正在生成的所有查詢。我曾嘗試將它放在初始化程序中,並且只是直接在控制檯中運行它,並且執行似乎不會執行。Rails 2.3單獨記錄所有數據庫查詢
我曾嘗試以下:
connection = ActiveRecord::Base.connection
class << connection
alias :original_exec :execute
def execute(sql, *name)
# try to log sql command but ignore any errors that occur in this block
# we log before executing, in case the execution raises an error
raise "THROW AN ERROR"
begin
file = File.open(RAILS_ROOT + "/log/sql.txt",'a'){|f| f.puts Time.now.to_s+": "+sql}
rescue Exception => e
;
end
# execute original statement
original_exec(sql, *name)
end
end
然後運行
Person.last
我仍然沒有錯誤。
第三個職位幫了我。謝謝 –