I spent an evening trying to figure out why my RAILS_ROOT environment variable was out of whack the other night. It turns out that it is set relative to where you launch WEBrick from.

Usually I launch WEBrick from the root of my application:

>ruby script/server

For some reason, the other night I thought it would be handy to open my command window right in the script directory. I could then just use:

>ruby server

But then I got errors which turned out to be caused by RAILS_ROOT being set wrong which throws everything out the window.

I did get the chance to use the console to debug though, which just reinforced how cool that guy is. Just fire up:

>ruby script/console

And at the prompt, type:

RAILS_ROOT

And low and behold, the value is there to see.

It turned out I figured out the issue when I fired up WEBrick the next night from my usual location and everything just worked again.