Rails 7我正在使用Rails.env.to_sym.遇到一些问题一些配置文件理解它,而有些文件则不理解它。
通过一些研究,我似乎可以为每个运行时环境生成不同的凭据文件。例如:
rails credentials:edit --environment development
rails credentials:edit --environment test这是否意味着Rails将根据rails环境设置(测试、开发等)选择适当的凭据文件?
发布于 2022-07-14 17:03:16
这是正确的,- the主凭证文件(credentials.yml.enc)被特定于环境的文件覆盖。
如果您从命令行运行bin/rails credentials:edit -h,您将看到以下内容:
=== Environment Specific Credentials
The `credentials` command supports passing an `--environment` option to create an environment specific override. That override will take precedence over the global `config/credentials.yml.enc` file when running in that environment. So:
bin/rails credentials:edit --environment development
will create `config/credentials/development.yml.enc` with the corresponding encryption key in `config/credentials/development.key` if the credentials file doesn't exist.我遇到了一个小问题--我试图生成特定于环境的凭据文件时遇到了一个错误(下面是错误的一部分):
`binwrite': No such file or directory @ rb_sysopen - config/credentials/test.yml.enc.tmp我的修正是先创建空文件夹(config/credentials),然后再重新运行命令(例如,bin/rails credentials:edit --environment test)。
https://stackoverflow.com/questions/72876613
复制相似问题