Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does RACK_ENV do in a Rails application?

I have a Rails application already in production. The guy before set these environment variables:

...
export RACK_ENV=none                                                                                                                  
export RAILS_ENV=production
...

What does RACK_ENV=none do? I can't find documentation on it anywhere. Do I need to set it in the Rails application or can I just delete that export?

like image 271
xx77aBs Avatar asked Oct 15 '14 11:10

xx77aBs


2 Answers

IMHO it's useless.

To find the current environment a Rails app first looks for the RAILS_ENV environment variable, then for RACK_ENV environment variable, then it defaults to 'development'.

like image 149
Fred Avatar answered Sep 18 '22 02:09

Fred


If you're using version 1.7 or later of the database_cleaner gem, and your CI server has RACK_ENV set to production like mine did, you'll need to set RACK_ENV to none (or anything other than production) to appease database_cleaner's safeguard that your tests aren't running in production. (Or you could disable the safeguard altogether, but that seems less safe.)

Looking at current rack source, it appears that the only value of RACK_ENV that is meaningful to rack is development, which causes rack to default the host to localhost instead of to 0.0.0.0. So it's foolish to set RACK_ENV to production in the first place, or to check that it's been set to that, but that foolishness has taken root all over.

like image 20
Dave Schweisguth Avatar answered Sep 21 '22 02:09

Dave Schweisguth