Rails ActiveRecord How Can I turn off logging particular queries

会有一股神秘感。 提交于 2019-12-11 03:19:52

问题


I am under developer mode in Rails.
I am trying to insert a record with binary data to DB using AR.

Edoc.create(
            :id_claim => @claim_index, 
            :id_material => @doc_code, 
            :size => @file_list.first[:size],
            :efile => params[:files][0].read
        )   

But It takes a lot of time because Rails logs that query with entire file content.

How Can I turn off logging particular queries?


回答1:


Try:

old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil
# your code here...

Restore logger:

ActiveRecord::Base.logger = old_logger; nil # nil just to suppress some garbage 


来源:https://stackoverflow.com/questions/10522961/rails-activerecord-how-can-i-turn-off-logging-particular-queries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!