rails3 console : how to get actual sql statements

In rails 2.3.5 world I get to see all the sql statements on my console. Thanks to following line of code in my ~/.irbc

if ENV['RAILS_ENV']   Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)) end

However above code does not do its magic in rails3 world.

In rails3 what do I need to do to see sql statements in my rails console.

All I know is that RAILS_ENV is now Rails.env and RAILS_DEFAULT_LOGGER is now Rails.logger

Maybe this helps you to find the solution :slight_smile:

Other than that I usually open a second Terminal window and do a

tail -f log/development.log

there I see the SQL statements which I evoked from the console. Usually even color coded.

Here there is a tip:

In order to make it work for both Rails 2 and Rails 3, my ~/irbrc looks like:

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

...not sure though if there is a better way to do that... bye.

(For Rails 3)

I have this in my development.rb environment file:

#log ActiveRecord ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console