[英]How to run 'rails credentials:edit' on Windows 10 without installing a Linux Subsystem
I am trying to run the following command on my Rails app on my Windows 10 machine:我正在尝试在我的 Windows 10 机器上的 Rails 应用程序上运行以下命令:
rails credentials:edit
But I get the following error message:但我收到以下错误消息:
No $EDITOR to open file in. Assign one like this:
没有 $EDITOR 来打开文件。像这样分配一个:
EDITOR="mate --wait" bin/rails credentials:edit
EDITOR="mate --wait" bin/rails 凭证:编辑
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.
对于立即 fork 和退出的编辑器,传递一个等待标志很重要,否则凭据将立即保存而没有机会进行编辑。
I did some research, and I understand that most people who want to run such aforementioned command on Windows 10 will need to install a Linux Subsystem on their Windows machines.我做了一些研究,我知道大多数想要在 Windows 10 上运行上述命令的人需要在他们的 Windows 机器上安装 Linux 子系统。 However, such option is not available for me because I don't have admin rights on my machine.
但是,这样的选项对我不可用,因为我在我的机器上没有管理员权限。 I have attempted installing a Linux subsystem by using resources like the one here without luck.
我曾尝试使用像这里这样的资源来安装 Linux 子系统,但没有运气。
I didn't find any of the answers above worked for me.我没有发现上面的任何答案对我有用。 Notepad complained about the directory being incorrect and gave me a blank file.
记事本抱怨目录不正确,并给了我一个空白文件。
I got it to work with Notepad++ by doing the following:我通过执行以下操作使其与 Notepad++ 一起使用:
SET EDITOR="C:\Program Files\Notepad++\notepad++.exe"
rails credentials:edit
I didn't need to use the --wait
flag.我不需要使用
--wait
标志。
I'm using VS Code and Powershell within VS Code, and this works for me:我在 VS Code 中使用 VS Code 和 Powershell,这对我有用:
> $env:EDITOR="code --wait"
> rails credentials:edit
Credit goes to this article https://flexpoint.tech/2020/05/16/editing-rails-6-0-credentials-on-windows/ by J. Pablo Fernández归功于 J. Pablo Fernández 撰写的这篇文章https://flexpoint.tech/2020/05/16/editing-rails-6-0-credentials-on-windows/
I would suggest you switch to non-windows based system if you're trying to do any rails development as I used to work on a windows machine until I caved in and switched entirely to Mate Linux.如果您尝试进行任何 Rails 开发,我建议您切换到基于非 Windows 的系统,因为我曾经在 Windows 机器上工作,直到我屈服并完全切换到 Mate Linux。 It would be so much easier to develop Rails application on Linux platform since you would see almost all gems compiling without any issue and all the rails terminal commands are working without further setup.
在 Linux 平台上开发 Rails 应用程序会容易得多,因为您会看到几乎所有 gems 编译都没有任何问题,并且所有 rails 终端命令都可以在没有进一步设置的情况下工作。
However, if you would like to edit your credentials, you need a text editor (Usually vim on Linux) setup before running credentials:edit.但是,如果您想编辑您的凭据,则需要在运行凭据之前设置文本编辑器(通常在 Linux 上为 vim):edit。
First run SET EDITOR="notepad_path"
and then try running rails credentials:edit
首先运行
SET EDITOR="notepad_path"
然后尝试运行rails credentials:edit
You can change notepad_path to any other text editor you prefer.您可以将 notepad_path 更改为您喜欢的任何其他文本编辑器。 However, some editors like Atom was giving weird issues for me.
然而,像 Atom 这样的一些编辑给我带来了奇怪的问题。
SET EDITOR="%windir%\\system32\\notepad.exe"
bundle exec rails credentials:edit
and notepad should come up with the decrypted infobundle exec rails credentials:edit
和记事本应该提供解密的信息If you are in a Windows environment, I highly recommend to use the classic notepad.如果您在 Windows 环境中,我强烈建议您使用经典记事本。 In my experience using Notepad++, sometimes it opened correctly but didn't save, instead it works perfect with the classic notepad.
根据我使用 Notepad++ 的经验,有时它可以正确打开但没有保存,而是与经典记事本完美配合。
Also to run those mentioned commands, better use the classic cmd shell console, it might not work properly in PS (Power Shell) console.同样要运行这些提到的命令,最好使用经典的 cmd shell 控制台,它可能无法在 PS(Power Shell)控制台中正常工作。 Good luck!
祝你好运!
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.
solution:解决方案:
$env:EDITOR="notepad"
rails credentials:edit
set EDITOR=subl --wait
set EDITOR="C:\filepath\to\your\editor --wait"
this time with quotes这次有引号
rails credentials:edit
[Windows 8.1] [视窗 8.1]
I'm using SET EDITOR="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
command to set the editor and it works.我正在使用
SET EDITOR="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
命令来设置编辑器并且它可以工作。
Next, just run rails credentials:edit
command.接下来,只需运行
rails credentials:edit
命令。 Then you can edit the credentials.yml
file.然后您可以编辑
credentials.yml
文件。 Save it and close the Notepad++ windows.保存并关闭 Notepad++ 窗口。 Then the credentials is encrypted and saved automatically.
然后凭据被加密并自动保存。
Got it working (using PowerShell) with让它工作(使用 PowerShell)
$env:EDITOR="notepad"
then然后
bundle exec rails credentials:edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.