views:

32

answers:

3

Hi,

I am using a simple query in ActiveRecord which does something like this.

MyTable.find(:all, :conditions => {:start_date => format_time(params[:date]) })

I want to get the equivalent query that is executed in the background, perhaps using a puts statement or something similar to that. MySQL is my database.

A: 

In development mode, your DB queries are printed to the server console, you can localize the query there.

clyfe
+3  A: 

You can see the SQL query that is executed by viewing the development log located in log/development.log. Note that the script/server command tails this log file by default.

  • In Rails 3 you can append a .to_sql method call to the end of the finder to output the SQL.

  • Alternatively, New Relic's free RPM Lite gem lets you see the SQL queries in developer mode as well as lots of other useful performance tuning information.

John Topley
But its so crowded in the log file. Is there anyway to separate it out.
Bragboy
+1  A: 

You can insatll mongrel

its gets you all sql queries on your terminal

or run active record query on script/console