gpt4 book ai didi

ruby-on-rails - RAILS_ENV 在哪里?

转载 作者:行者123 更新时间:2023-12-03 23:14:04 29 4
gpt4 key购买 nike

我正在看这篇关于 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 the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE 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
  • 找 key foo在 database.yml 中。
  • Rails.env.foo?会是真的。

  • 因此,Rails 的环境概念与一般的计算概念有些不同——Rails 环境是一组用于不同目的(例如自动化测试或生产)的设置和数据库的更广泛的术语。

    也可以看看:
  • Store config in the environment
  • 关于ruby-on-rails - RAILS_ENV 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43863251/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com