Wednesday, September 5, 2012

Beware require_directory

I prefer require_directory in manifest.coffee to straight require, because it does more for me, but letting Rails do things for you is always a mixed blessing. Tonight I spent an hour and a half trying to figure out why code ran on my machine but spewed asset pipeline fail on somebody else's machine.

The answer was require_directory. I had a Backbone app with a models directory I emptied out but never threw away. This made the directory completely invisible to git, because:

Git doesn't ignore empty directories. It ignores all directories. In Git, directories exist only implicitly, through their contents. Emtpy directories have no contents, therefore they don't exist.

Sometimes it's better to swallow your pride and use require. Also: unfuck your habitat applies to code as well. I should have cleared out the manifest, and the directory, when I cleared out the models.