当我这样做
bin/rails credentials:edit
时,我的编辑器会打开一个像credentials.yml.enc.1234
这样的文件,其中包含默认内容。完成编辑后,我点击保存,控制台显示 New credentials encrypted and saved.
在我再次运行
bin/rails credentials:edit
后,另一个临时文件被打开(credentials.yml.enc.4321
)并且内容恢复为默认值。
我怎样才能使凭据持久化?
如果你没有使用
vim
,你需要在编辑器中添加一个wait
标志。
例如
atom
:
EDITOR="atom --wait" rails credentials:edit
我遇到了同样的事情并找到了答案here.
我在使用 atom 作为编辑器时也遇到了这个问题。 我试过:
EDITOR="atom --wait" rails credentials:edit
和
EDITOR="atom -w" rails credentials:edit
但没有结果。最后,我使用了 nano (ubuntu):
EDITOR="nano" rails credentials:edit
对我来说,这很好用。也许,作为替代方案,它会对某人有所帮助。
有一个与此相关的问题: https://github.com/rails/rails/issues/31286
已经在 5.2.0.rc1 中修复了
我在使用 textmate 作为编辑器的 Rails 5.2.0 中遇到了这个问题。事实证明,凭证文件必须在保存后关闭才能使更改持续存在。
您可以使用以下命令在 sublime 中打开凭据文件。
EDITOR="subl --wait" bin/rails credentials:edit
确保在进行更改后关闭 sublime 中的凭据文件。 同时重新启动服务器以查看更改。
由于我没有将 EDITOR 大写,所以我在这方面遇到了一些困难。命令
editor="vim" rails credentials:edit
直接保存凭据,没有机会编辑。该指南告诉您添加 --wait 标志。对我来说,这与 --wait 标志无关,而与大写有关。这是有效的:
EDITOR="vim" rails credentials:edit
(不——等一下,但大写的 EDITOR)
我自己遇到了一些麻烦,最终在 OS X 上使用 TextEdit 解决了所有问题。
EDITOR="open -a TextEdit --wait" rails credentials:edit
打开编辑但保存并关闭文件后,我仍然没有得到保留的更改。我还需要退出 TextEdit。
所以如果你想在 OS X Ventura 上使用 TextEdit 编辑凭据,你可以使用上面的命令来完成,然后保存文件,然后退出 TextEdit。