Rails app卡在开发环境中

时间:2014-09-08 19:27:35

标签: ruby-on-rails ruby-on-rails-4 environment-variables

我遇到了一个Rails应用程序的问题,我刚尝试部署,我似乎无法搞清楚。即使设置了RAILS_ENV = production,Rails也只想在开发中启动。例如:

$ 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。有人有任何想法吗?感谢

1 个答案:

答案 0 :(得分:2)

哇。刚才回答我的问题,答案就像砖墙一样打击我:

ENV['GOOGLE_ANALYTICS_ID'] = 'UA-XXXXXXXX-2' if Rails.env == 'development'

不是这样:

ENV['GOOGLE_ANALYTICS_ID'] = 'UA-XXXXXXXX-2' if Rails.env = 'development'

道德:检查你的等号。