Rails WEBrick shows raw SQL statements for any ActiveRecord activities. How to enable that in the console?
To do this you have to enable logger, you could do this as follows.
Open the rails console:
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
Have a look at this link:
http://rubyquicktips.com/post/292826666/display-activerecord-generated-sql-queries-in-the
A similar way to achieve this without resorting to digging into ActiveRecord
internals and using instance variables is to just access the config
object that Rails gives you. Place this inside config/application.rb
:
config.logger = Logger.new(STDOUT) if($0 == 'irb' || $0 == 'script/rails')
Go to your console.rb
location /lib/rails/console.rb
Look for ActiveRecord::Base.connection.instance_variable_set
Change it to following
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With