Posted By

batamire on 12/19/10


Tagged

sql rails console log rails3


Versions (?)

SQL log in Rails console


 / Published in: Rails
 

  1. # for rails 2
  2. if ENV.include?('RAILS_ENV')
  3. if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
  4. require 'logger'
  5. Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
  6. end
  7.  
  8. def sql(query)
  9. ActiveRecord::Base.connection.select_all(query)
  10. end
  11. # for rails 3
  12. elsif defined?(Rails) && !Rails.env.nil?
  13. if Rails.logger
  14. Rails.logger = Logger.new(STDOUT)
  15. ActiveRecord::Base.logger = Rails.logger
  16. end
  17. end

Report this snippet  

You need to login to post a comment.