This project is archived and is in readonly mode.

#2799 ✓wontfix
Ryan Bigg

SQL Display

Reported by Ryan Bigg | June 13th, 2009 @ 11:18 AM | in 2.x

I wrote a plugin called SQL Display a couple of days ago and since showing it off to some people, they've suggested that this should be in Rails core as it's helpful for debugging purposes. Admittedly, the code isn't "beautiful" and I'm sure someone can figure out a better way than I've done it but... I don't want to go into the effort of writing a patch for this and having it bounced. So who else thinks having this functionality in Rails is a good idea?

Comments and changes to this ticket

  • Bodaniel Jeanes

    Bodaniel Jeanes June 13th, 2009 @ 11:04 AM


    I've wanted this for a while...

  • mark (at

    mark (at June 13th, 2009 @ 11:22 AM

    +1 i was just about to make a similar plugin.

  • mib_s2d5o9

    mib_s2d5o9 June 13th, 2009 @ 11:25 AM

    +1 this would make my life convenient - add to Core

  • David Knorr

    David Knorr June 13th, 2009 @ 12:33 PM

    +1 However, I agree with you that it probably would be better to use a less hack-ish attempt. I don't know exactly how you'd implement this, but something like setting an instance variable in the sql method and then checking if it's true in whatever method in ActiveRecord that takes care of performing SQL queries, would be cool.

  • Morten

    Morten June 13th, 2009 @ 06:24 PM

    Rails.logger.silence(Logger::DEBUG) do
    Account.count end

    The block returns the last statement of the block, which is expected behavior (or more intuitive at least). You get the SQL printed in your .log file, regardless of environment.

    To be desired would be nicer semantics on setting the log level for Rails.logger eg. at_level(level = Logger::INFO), and reimplement "silence" to call that with Logger::ERROR instead.

  • Ryan Bigg

    Ryan Bigg June 14th, 2009 @ 10:08 AM


    Your code does not do what you say it does, for me it prints out the output of the count rather than the SQL.

    I've hacked some more today on sql_display and now I'm overriding methods in ActiveRecord in the plugin. I revoke my idea of putting this plugin into core, since it will involve too many if statements.

  • Pratik

    Pratik June 14th, 2009 @ 11:20 AM

    • State changed from “new” to “wontfix”

    This should be in mailing list really. I just use 3 lines in my ~/.irbrc for this :

    def log_to(stream=$stdout)
      ActiveRecord::Base.logger =
  • Morten

    Morten June 14th, 2009 @ 01:33 PM

    Ryan, I suppose I misunderstood your intention. You want the SQL in hand, I want to be able to log it regardless of environment.

  • bingbing

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

People watching this ticket