简体   繁体   English

设置了RAILS_ENV,但Rails.env不同

[英]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. 我认为我已经尽力尝试并为Rails应用程序实际设置环境了。

In .htaccess 在.htaccess中

RailsEnv production (produces a 500 server error)

In environment.rb 在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... 我正在使用bluehost ...但是直到昨天为止一切都很好...我认为我没有进行任何更改...

EDIT: Sorry, forgot to mention that it's Rails v2 编辑:对不起,忘了提到它是Rails v2

Also, depending on where I set the RAILS_ENV variable in environment.rb, I get errors. 另外,根据我在environment.rb中设置RAILS_ENV变量的位置,我会得到错误。 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 [2011年7月26日星期二11:42:20] [警告] [客户端xxxx](104)由对等方重置的连接:mod_fcgid:从FastCGI服务器读取数据时出错
[Tue Jul 26 11:42:20 2011] [error] [client xxxx] Premature end of script headers: dispatch.fcgi [2011年7月26日星期二11:42:20] [错误] [客户端xxxx]脚本头的结尾过早: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". 编辑3:检查ENV ['RAILS_ENV'],我看到“生产”,但是当直接检查RAILS_ENV时,我看到“开发”。

According to the passenger docs , RailsEnv works in .htaccess only if AllowOverride Options is set. 根据旅客文档 ,仅在设置AllowOverride Options的情况下,RailsEnv才能在.htaccess中工作。 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)). 我在主应用程序的内部一个名为“ generate”的文件夹中嵌套了一个应用程序(猜测那是怎么回事:S(nub-ness))。 Among other things, empty cgi-bin folders lying around and an empty dispatch.fcgi file in my public directory. 除其他外,我周围的空cgi-bin文件夹和公共目录中的空dispatch.fcgi文件。 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. 总之,长话短说,解决方案是将我的应用程序目录与新的Rails应用程序进行比较并删除所有内容。 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. 我还将全新的调度文件从新应用程序复制到了当前应用程序,并且从database.yml文件中删除了所有注释和多余的换行符。 Character and file formatting might have also played a part somewhere (my bluehost tech support said). 字符和文件格式可能也在某处发挥了作用(我的bluehost技术支持说)。 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. 另外,我从.htaccess中注释掉了“ AddHandler fcgid-script .fcgi”-我之前没有做过此事……所以我猜想,加上弹簧清洁解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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