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.

# Render SQL in Rails Console
if "irb" == $0
  require 'logger'
  if ENV.include?('RAILS_ENV')&&
  !Object.const_defined?('RAILS_DEFAULT_LOGGER')
     Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
  else
     ActiveRecord::Base.logger = Logger.new(STDOUT)
  end
end