Is there any gem which works on Rails 3 that can show which part of my code generated which SQL query?
On Rails 2.3 there was plugin called query_trace, but it doesn’t seem to work on Rails 3, it generates following error:
alias_method': undefined method `log_info' for class `ActiveRecord::ConnectionAdapters::AbstractAdapter' (NameError)
QueryTrace doesn’t work as-is because many changes were made in Rails 3 esp in the area of ActiveRecord.
So, hacking around, I made it work like this:
You just need the 2 files below in the locations mentioned. Then restart the web server.
After the SQL, you should see
Called from:in a console (magenta on white) and log fileIn
/vendor/plugins/query_trace/lib/query_trace.rbIn
/vendor/plugins/query_trace/init.rb