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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 :) 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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Franco Sellitto
2010-Aug-18 13:33 UTC
Re: rails3 console : how to get actual sql statements
Here there is a tip: http://rubyquicktips.tumblr.com/post/292826666/display-activerecord-generated-sql-queries-in-the 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
(For Rails 3) I have this in my development.rb environment file: #log ActiveRecord ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.