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
我仍然没有错误。
第三个职位帮了我。谢谢 –