8

I am using debugger gem in my Rails 3.2 application.

How do I view the resulting SQL statement of active record method calls on the debug console?

For eg: If I run Product.all on the debug console it prints out all the products. I would also like to see the "Select * from Products" as well. Is this possible?

Edit Now that I am wiser(;p) active record also provides .to_sql method on the active record relation objects, to inspect the sql queries that they run against the underlying database.

1 Answer 1

21

Yep, you bet - just run this before your commands:

ActiveRecord::Base.logger = Logger.new(STDOUT)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. That really helps. Btw, do you know anything that would save me some key strokes and set stuff like these up automatically or by a shorter named method call?
Not sure, you could try to stick it into your /config/environments/development.rb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.