简体   繁体   中英

RAILS_ENV set but Rails.env is different

I think I've exhausted all I could find to try and actually set the environment for my rails app.

In .htaccess

RailsEnv production (produces a 500 server error)

In environment.rb

ENV['RAILS_ENV'] ||= 'production' #does not set RAILS_ENV
ENV['RAILS_ENV'] = 'production' #sets RAILS_ENV to 'production', but Rails.env stays at 'development'

I'm using bluehost...but everything's been working just fine up until yesterday...I don't think I made any changes...

EDIT: Sorry, forgot to mention that it's Rails v2

Also, depending on where I set the RAILS_ENV variable in environment.rb, I get errors. If I put it in the place where I'm told it's supposed to be, I get the error:

[Tue Jul 26 11:42:20 2011] [warn] [client xxxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Jul 26 11:42:20 2011] [error] [client xxxx] Premature end of script headers: dispatch.fcgi

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION

ENV['RAILS_ENV'] = "production" unless (File.expand_path(File.dirname(__FILE__)) =~ /MyProductionFolder/).nil?
require File.join(File.dirname(__FILE__), 'boot')
ENV['GEM_PATH'] = '/home/usr/ruby/gems'

If I put it AFTER the boot join, the variable gets set but the actual environment doesn't change.

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION

require File.join(File.dirname(__FILE__), 'boot')
ENV['RAILS_ENV'] = "production" unless (File.expand_path(File.dirname(__FILE__)) =~ /MyProductionFolder/).nil?
ENV['GEM_PATH'] = '/home/usr/ruby/gems'

EDIT #3: Inspecting ENV['RAILS_ENV'], I see "production", but when inspecting RAILS_ENV directly, I see "development".

According to the passenger docs , RailsEnv works in .htaccess only if AllowOverride Options is set. Have you checked if that's the case?

It turns out I had a whole whack of garbage files and folders lying around from earlier failed attempts at creating the app. I had nested an app in a folder called 'generate' within my main app (guess how THAT happened :S (nub-ness)). Among other things, empty cgi-bin folders lying around and an empty dispatch.fcgi file in my public directory. I have NO IDEA how that got there, I swear.

Anyways, long story short the solution was to compare my app directory to a fresh rails app and delete all the cruft. I also copied over the brand-new dispatch files from the new app to my current app and I took out all comments and superfluous line breaks from my database.yml file. Character and file formatting might have also played a part somewhere (my bluehost tech support said). Also, I commented out "AddHandler fcgid-script .fcgi" from my .htaccess - I had done this before to no effect...so I'm guessing THAT coupled with spring cleaning fixed my issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM