ruby-on-railsruby-on-rails-3

How to display the origin of an SQL query in the rails server console?


In development mode, I would like to be able to see in the console where an SQL query was fired.

What is currently showing up in my console (dumb example query)

User Load (1.7ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 65 LIMIT 1

What I would like to see

application_controller.rb:68
User Load (1.7ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 65 LIMIT 1

Solution

  • checkout https://github.com/RISCfuture/sql_origin for a gem that provides that.