I’m not going to open the can of worms that is “Rails Magic (TM)”, but sometimes you need to track down why Rails is doing something that you don’t expect it to.
A form helper I was using was unexpectedly loading all objects from the database rather than just the ones I passed it. Turns out I was actually passing it a nil object, but whilst I was investigating I came across the neat plugin QueryTrace.
QueryTrace gives you log output with a backtrace of where the query came from, allowing you to track down rogue queries:
1 2 3 4 5 6 7 8 9
It is installed as a plugin using
As this Pivotal Labs blog post suggests, the plugin can also be useful for load or performance but may slow down the rest of your app whilst it is being run.