SQL Logging to script/console
When running a Rails console session, a true time saver is directing the ActiveRecord logs to STDOUT instead of the log file. This is easily accomplished adding the following to your ~/.irbrc file:
if rails_env = ENV['RAILS_ENV'] # Called after the irb session is initialized and Rails has # been loaded (props: Mike Clark). IRB.conf[:IRB_RC] = Proc.new do ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Base.instance_eval { alias :[] :find } end end
If someone knows the original author of these lines, let me know and I’ll give them proper attribution.