[英]How to run 'rails credentials:edit' on Windows 10 without installing a Linux Subsystem
我正在尝试在我的 Windows 10 机器上的 Rails 应用程序上运行以下命令:
rails credentials:edit
但我收到以下错误消息:
没有 $EDITOR 来打开文件。像这样分配一个:
EDITOR="mate --wait" bin/rails 凭证:编辑
对于立即 fork 和退出的编辑器,传递一个等待标志很重要,否则凭据将立即保存而没有机会进行编辑。
我做了一些研究,我知道大多数想要在 Windows 10 上运行上述命令的人需要在他们的 Windows 机器上安装 Linux 子系统。 但是,这样的选项对我不可用,因为我在我的机器上没有管理员权限。 我曾尝试使用像这里这样的资源来安装 Linux 子系统,但没有运气。
我没有发现上面的任何答案对我有用。 记事本抱怨目录不正确,并给了我一个空白文件。
我通过执行以下操作使其与 Notepad++ 一起使用:
SET EDITOR="C:\Program Files\Notepad++\notepad++.exe"
rails credentials:edit
我不需要使用--wait
标志。
我在 VS Code 中使用 VS Code 和 Powershell,这对我有用:
> $env:EDITOR="code --wait"
> rails credentials:edit
归功于 J. Pablo Fernández 撰写的这篇文章https://flexpoint.tech/2020/05/16/editing-rails-6-0-credentials-on-windows/
如果您尝试进行任何 Rails 开发,我建议您切换到基于非 Windows 的系统,因为我曾经在 Windows 机器上工作,直到我屈服并完全切换到 Mate Linux。 在 Linux 平台上开发 Rails 应用程序会容易得多,因为您会看到几乎所有 gems 编译都没有任何问题,并且所有 rails 终端命令都可以在没有进一步设置的情况下工作。
但是,如果您想编辑您的凭据,则需要在运行凭据之前设置文本编辑器(通常在 Linux 上为 vim):edit。
首先运行SET EDITOR="notepad_path"
然后尝试运行rails credentials:edit
您可以将 notepad_path 更改为您喜欢的任何其他文本编辑器。 然而,像 Atom 这样的一些编辑给我带来了奇怪的问题。
SET EDITOR="%windir%\\system32\\notepad.exe"
bundle exec rails credentials:edit
和记事本应该提供解密的信息如果您在 Windows 环境中,我强烈建议您使用经典记事本。 根据我使用 Notepad++ 的经验,有时它可以正确打开但没有保存,而是与经典记事本完美配合。
同样要运行这些提到的命令,最好使用经典的 cmd shell 控制台,它可能无法在 PS(Power Shell)控制台中正常工作。 祝你好运!
No $EDITOR to open file in. Assign one like this:
EDITOR="mate --wait" bin/rails credentials:edit
For editors that fork and exit immediately, it's important to pass a wait flag,
otherwise the credentials will be saved immediately with no chance to edit.
解决方案:
$env:EDITOR="notepad"
rails credentials:edit
set EDITOR=subl --wait
set EDITOR="C:\filepath\to\your\editor --wait"
这次有引号
rails credentials:edit
[视窗 8.1]
我正在使用SET EDITOR="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
命令来设置编辑器并且它可以工作。
接下来,只需运行rails credentials:edit
命令。 然后您可以编辑credentials.yml
文件。 保存并关闭 Notepad++ 窗口。 然后凭据被加密并自动保存。
让它工作(使用 PowerShell)
$env:EDITOR="notepad"
然后
bundle exec rails credentials:edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.