Rails view activerecord sql statements on debug console

戏子无情 提交于 2019-12-05 02:46:14

问题


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:


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

ActiveRecord::Base.logger = Logger.new(STDOUT)


来源:https://stackoverflow.com/questions/12346192/rails-view-activerecord-sql-statements-on-debug-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!