ruby-on-rails - 为什么我的 Rails 应用程序打不开?即使我使用命令($ heroku config:set ~ 等)设置了环境变量 'SECRET_KEY_BASE'
问题描述
我的ruby版本是2.6.6,我的mysql版本是8.0.23,我的mysql2版本是0.5.3,我的bundler版本是2.2.21,我的rails版本是5.0.7.2,我的Xcode版本是12.5。
我使用 macOS Big Sur(11.4 版)和文本编辑器“Atom”。
我计划使用 HEROKU 的 URL 发布我的 Rails 应用程序(例如 https://[My APP Name].herokuapp.com)。
我运行了以下命令。
$ heroku open
发生以下错误。
An unhandled lowlevel error occurred. The application logs may have details.
我运行了以下命令。
$ heroku logs
#<RuntimeError: Missing
`secret_key_base` for 'production' environment, set this value in `
config/secrets.yml`>
我使用以下命令设置了两个环境变量:$ heroku config:set [ENVIRONMENT VARIABLE NAME]。
$ heroku config:set DATABASE_USERNAME=****
$ heroku config:set DATABASE_PASSWORD=****
我的 config/secrets.yml 文件如下所示。
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
我运行了以下命令。
$ bundle exec rake secret
GENERATED_CODE
我运行了以下命令。
$ heroku config:set SECRET_KEY_BASE=GENERATED_CODE
Setting SECRET_KEY_BASE and restarting ⬢ [My APP Name]... done, v24
SECRET_KEY_BASE: GENERATED_CODE
我如下设置环境变量SECRET_KEY_BASE
。
$ vi /etc/profile
SECRET_KEY_BASE
我在 Vim 编辑器中设置了如下环境变量。
-- INSERT --
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
if [ -d /etc/profile.d ]; then
# commands go here
fi
if [ -f /etc/profile ]; then
# commands go here
fi
if [ -d /etc/profile.d -a -f /etc/profile ]; then
# both are true
fi
if [ -d /etc/profile.d -o -f /etc/profile ]; then
# at least one is true
fi
export SECRET_KEY_BASE=GENERATED_CODE
我使用以下两个命令保存了上述SECRET_KEY_BASE
内容并结束了 Vim 编辑器。
:w !sudo tee %
:q!
我使用以下命令再次打开 vim 编辑器$ vi /etc/profile
:
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
if [ -d /etc/profile.d ]; then
# commands go here
fi
if [ -f /etc/profile ]; then
# commands go here
fi
if [ -d /etc/profile.d -a -f /etc/profile ]; then
# both are true
fi
if [ -d /etc/profile.d -o -f /etc/profile ]; then
# at least one is true
fi
export SECRET_KEY_BASE=GENERATED_CODE
我运行了以下命令。
$ vi ~/.bash_profile
我在~/.bash_profile
.
export SECRET_KEY_BASE=GENERATED_CODE
~
~
~
~
~
~
~
~
~
~
~
~
"~/.bash_profile" 1L, 152B
我保存了上面的内容SECRET_KEY_BASE
,使用Esc然后“ :x
”和Enter。
我验证环境变量SECRET_KEY_BASE
在 Linux 中设置正确。因为我运行了以下三个命令。
$ printenv | grep SECRET_KEY_BASE
SECRET_KEY_BASE=GENERATED_CODE
$ echo $SECRET_KEY_BASE
GENERATED_CODE
$ heroku config
=== [My APP Name] Config Vars
DATABASE_PASSWORD: ****
DATABASE_URL: postgres://****
DATABASE_USERNAME: ****
HEROKU_POSTGRESQL_AQUA_URL: postgres://****
HEROKU_POSTGRESQL_BLACK_URL: postgres://****
LANG: en_US.UTF-8
RACK_ENV: production
RAILS_ENV: production
RAILS_LOG_TO_STDOUT: enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE: GENERATED_CODE
我检查了是否有/etc/profile.d
目录和/etc/profile
文件。因为我运行了以下命令。
$ sudo ls -lh /etc/profile
-r--r--r-- 1 DATABASE_USERNAME wheel 599B Aug 8 15:08 /etc/profile
我运行了以下命令。
$ heroku open
Web 浏览器中出现以下错误。
An unhandled lowlevel error occurred. The application logs may have details.
我运行了以下命令。
$ heroku logs
#<RuntimeError: Missing
`secret_key_base` for 'production' environment, set this value in `config/secrets.yml`>
为什么我的 Rails 应用程序打不开?即使我使用以下命令设置了环境变量“SECRET_KEY_BASE”。
$ heroku config:set SECRET_KEY_BASE=GENERATED_CODE
$ vi /etc/profile
$ vi ~/.bash_profile
解决方案
推荐阅读
- javascript - 有没有办法获取使用 ContentResolver.loadThumbnail 创建的位图的文件路径?
- github-actions - 当 repo 主题更改时触发 github 操作工作流
- python - 如何使用 plotly.express 创建一个共享 x 轴的条形图,顶部有字幕?
- vue.js - 在Vue中的div内添加组件
- java - java中二维数组的输出,(取这个错误[[Z@6d06d69c)
- python - 使用 3D 阵列的 3D 颤动图视频
- quarkus - 使用 RestClient 时出现 ContextNotActiveException
- pivot - 当仅存在一个详细信息行时,如何抑制 Google Data Studio 数据透视表小计
- json - 在 aws cli 响应中将 Linux Shell 脚本“&”替换为 \u0026
- multidimensional-array - 在 awk 中填充和解析二维数组