Debugging SQL queries in rails console

When pasting ActiveRecord::Base.logger = Logger.new(STDOUT) into the rails console, it will convert all active record queries into raw SQL.

This is helpful to make sure active record queries are optimized (avoid n+1) or quickly grab an SQL statement for database software.

A great tip to keep in your back pocket!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright Loving to Code 2025
Tech Nerd theme designed by Siteturner