Thursday, September 9, 2010

Rails Double loading

<code>Rails console work revealed a rails file being loaded twice but some of the code was external to me. So, I could not really
where it was coming from. Jason King had this nice tip.

</code>

It looks like things are being loaded twice. Not sure what `config/preinitializer.rb` is (part of your own project?) but obviously rack shouldn't be loaded twice. This can happen if two things are requiring the same file in different ways the only way that `require` protects you from multiple-loading is a string comparison of what was required. Eg. require 'redcloth' and require 'RedCloth' will both succeed.

The simplest way to resolve this is to edit the files that are being loaded, and at the very top of them (to debug) just put this:

y caller

Then just fire up your console, and you should get a stack trace of where the files are being loaded from. You might find multiple load points in your project, or at least some hints as to where to look for the double-loading.