Xavier
Xavier

Reputation: 3513

Rails app stuck in development environment

I'm encountering a problem with a Rails app I just tried to deploy that I just can't seem to figure out. Rails wants to start only in development, even if RAILS_ENV=production is set. For example:

$ 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

Notice how puma correctly starts in production, but rails itself starts in development? Very strange. That "Finished setting environment variables" is from the following little script in my 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

It sets environment variables based on a local_env.yml file I have, which does not include RAILS_ENV. Does anyone have any ideas here? Thanks

Upvotes: 0

Views: 432

Answers (1)

Xavier
Xavier

Reputation: 3513

Wow. Reviewing my question just now, the answer hit me like a brick wall:

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

NOT THIS:

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

Moral: check your equal signs.

Upvotes: 2

Related Questions