[Mongrel] first request always fails

Jeroen Houben jeroen at supercool.nl
Sun Sep 3 11:45:52 EDT 2006

Zed Shaw wrote:
> But, why are you using ENV?  You could just use any constant you want in
> environment.rb.  Try making a SITE_CONFIG = {'site' => 'stuff.com'} and
> see if that works instead.

The reason I'm using it is because I'm running multiple sites from one 
rails app. I'm trying to pass some sort of variable to each mongrel upon 
startup  to indicate which subdomain (and thus which client) each 
mongrel belongs to. I'm sure there is a better and DRYer way to so this, 
but I haven't found it yet.

Anyway, then in environment.rb I do something like this:

# Set the SITE constant. Defaults to 'demo'
SITE = ENV['site ? ENV['site'] : 'demo

## initialize site specific information
globals_file = File.join(File.dirname(__FILE__), 

if File.exist?(globals_file)
   require globals_file

The SITE constant is also used in database.yml

> In truth, getting site config values from ENV is kind of a no-no since
> you can't trust ENV.  It's the reason a lot of programs clear ENV before
> starting other programs.

Yeah I figured it wasn't the best way, but it worked for my 
lighty+fastcgi setup so I never really thought about it anymore.

Thanks for replying so quickly btw!


More information about the Mongrel-users mailing list