我正在看这篇关于 rake 命令的文章,但不知道 RAILS_ENV 在哪里。那是在某个特定文件中吗?
db:create Creates the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases.
最佳答案
RAILS_ENV
只是在 shell 或操作系统本身(或在调用进程时)设置的环境变量。
Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer.
They are part of the environment in which a process runs. For example, a running process can query the value of theTEMP
environment variable to discover a suitable location to store temporary files, or theHOME
orUSERPROFILE
variable to find the directory structure owned by the user running the process.
https://en.wikipedia.org/wiki/Environment_variable
ENV["RAILS_ENV"]
只包含一个字符串,例如“生产”、“开发”或“测试”。这告诉 Rails which configuration file在 /config/environments
加载 - 以及 database.yml
中的哪个哈希键用于数据库。例如如果
ENV["RAILS_ENV"] == "foo"
Rails 将:/config/environments/foo.rb
foo
在 database.yml 中。 Rails.env.foo?
会是真的。 因此,Rails 的环境概念与一般的计算概念有些不同——Rails 环境是一组用于不同目的(例如自动化测试或生产)的设置和数据库的更广泛的术语。
也可以看看:
关于ruby-on-rails - RAILS_ENV 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43863251/