22 Apr 2012

Note: How to show SQL in Rails Console

Just add the following lines into  config/environment.rb. This switches default logger to STDOUT.

  1. # Render SQL in Rails Console  
  2. if "irb" == $0  
  3.   require 'logger'  
  4.   if ENV.include?('RAILS_ENV')&&  
  5.   !Object.const_defined?('RAILS_DEFAULT_LOGGER')  
  6.      Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))  
  7.   else  
  8.      ActiveRecord::Base.logger = Logger.new(STDOUT)  
  9.   end  
  10. end