Toshimaru's Blog

Show SQL queries in rails console

When you set log_level :info (mostly on production server), the SQL outputs are disabled in rails console.

# Rails Configuration
Rails.application.configure do
  ...
  config.log_level = :info
  ...
end
> Model.count
=> 12345

If you want to see SQL generated by Model.count, you need to set logger level manually.

Rails.logger.level = :debug
> Rails.logger.level = :debug
=> :debug

> Model.count
   (1.8ms)  SELECT COUNT(*) FROM `models`
=> 12345

Now, you can check the queries in rails console.

Reference