Reputation: 4802
I need to set the port of unicorn depending of environment. Something like this:
#config/unicorn.rb
if Rails.env.production?
listen 8080, :tcp_nopush => true
elsif Rails.env.staging?
listen 3001, :tcp_nopush => true
end
above code return this error:
[out :: 172.30.1.24] config/unicorn.rb:32:in `reload': uninitialized constant Unicorn::Configurator::Rails (NameError)
How to change the port according with the environment?
Ty!
Upvotes: 1
Views: 2885
Reputation: 1834
It looks like you might have a namespace lookup problem. Your code is being evaluated in the context of Unicorn::Configurator
, and you have a "bare word constant lookup" for Rails
in your conditional (the if Rails.env
part). You can force a top-level lookup by using ::Rails
instead:
if ::Rails.env.production?
# etc.
end
Hope that helps.
Upvotes: 0
Reputation: 18794
You'll need to load your Rails environment to get access to Rails.env:
# config/unicorn.rb
require File.dirname(__FILE__)+'/application'
port = case Rails.env
when 'production' then 8080
when 'staging' then 3001
else 3000
end
listen port, :tcp_nopush => true
Upvotes: 0
Reputation: 11929
try to check environment variables
environment = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'production'
Upvotes: 2