I want to get the current enviroment of my rails application. But I don't konw what's different between RACK_ENV and RAILS_ENV? Who can help me?
Why sometimes RACK_ENV is empty, but RAILS_ENV has value?
You can use RACK_ENV as well as RAILS_ENV except for RAILS_ENV is prior to RACK_ENV.
rails/rails.rb at b0b4b176b0e061a4f03ddce669637b7d6c37aa33 · rails/rails
Rails applications uses RAILS_ENV
. Other Rack-based applications use RACK_ENV
. If you have a Rails application, ignore RACK_ENV
.
EDIT: The other answer is more correct.
def set_environment
ENV["RAILS_ENV"] ||= options[:environment]
end
ENV["RAILS_ENV"] is from options
def options
merged_options = @use_default_options ? default_options.merge(@options) : @options
merged_options.reject { |k, v| @ignore_options.include?(k) }
end
if default rails server, environment is from default options
def default_options
environment = ENV['RACK_ENV'] || 'development'
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
{
:environment => environment,
:pid => nil,
:Port => 9292,
:Host => default_host,
:AccessLog => [],
:config => "config.ru"
}
end
so, ENV['RACK_ENV'] has default value 'development'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With