Reputation: 6858
i.e. when I'm running the app in test mode (using rails server) or maybe some other configuration it's running in develop mode (with no asset compilation, or caching, etc) but when I deploy it to a server its running in production mode.
How does the app determine what environment configuration to use?
Upvotes: 6
Views: 2389
Reputation: 29281
Rails reads the current environment from the operating system's environment variables by checking the following in order of priority:
RAILS_ENV
environment variable by calling ENV["RAILS_ENV"]
ENV["RACK_ENV"]
"development"
You can see that behavior in the Rails source code by looking at the definition of the Rails.env
method:
def env
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
Source: https://github.com/rails/rails/blob/4-0-stable/railties/lib/rails.rb#L55-L57
That's the method you call when you write Rails.env
to find out the current environment.
Upvotes: 14