ruby-on-rails - RAILS_ENV 在哪里?

标签 ruby-on-rails

我正在看这篇关于 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/

    相关文章:

    ruby-on-rails - 是否可以将 HTTParty 请求结果作为对象使用

    ruby-on-rails - 验证错误消息散列为空

    ruby-on-rails - 如何在传递 block 的同时渲染非部分布局?

    ruby-on-rails - Ruby 中的 IBM Watson NLU

    ruby-on-rails - 由于错误的默认语言环境,我的 Rails 应用程序规范随机失败

    ruby-on-rails - Rails 应用程序中的默认 Sidekiq Redis 配置

    mysql - 尽管有 my.cnf 设置,Rake db :create continues to use/tmp/mysql. socks

    ruby-on-rails - 在 Rails 6 上渲染 js.erb View

    ruby-on-rails - 空 Rails 应用程序中的内存无限增长

    ruby-on-rails - gem 安装 kgio 错误