【发布时间】:2014-11-02 02:39:00
【问题描述】:
我刚刚尝试部署的 Rails 应用程序遇到了一个问题,我似乎无法弄清楚。 Rails 希望仅在开发中启动,即使设置了 RAILS_ENV=production。例如:
$ rails s --environment=production
Finished setting environment variables
=> Booting Puma
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Puma 2.9.0 starting...
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:3000
注意 puma 是如何在生产中正确启动的,但 rails 本身是在开发中启动的?很奇怪。 “已完成设置环境变量”来自我的 application.rb 中的以下小脚本:
config.before_configuration do
env_file = File.join(Rails.root, 'config', 'local_env.yml')
YAML.load(File.open(env_file)).each do |key, value|
ENV[key.to_s] = value
end if File.exists?(env_file)
ENV['GOOGLE_ANALYTICS_ID'] = 'UA-XXXXXXXX-2' if Rails.env = 'development'
puts "Finished setting environment variables"
end
它根据我拥有的 local_env.yml 文件设置环境变量,该文件不包含 RAILS_ENV。有人在这里有什么想法吗?谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 environment-variables