简体   繁体   English

Secrets.yml 未在 Rails 中加载

[英]Secrets.yml is not loading in rails

I have some data in my local secrets.yml .我的本地secrets.yml有一些数据。 Now I have added 2 more secrets, but in rails console these secrets are not coming.现在我又添加了 2 个秘密,但在 Rails 控制台中,这些秘密不会出现。 Even I edit old keys in the secrets.yml and then open console again but still not able to view the updated data.即使我在 secrets.yml 中编辑旧密钥,然后再次打开控制台,但仍然无法查看更新的数据。 It means that secrets.yml is not loading properly.这意味着 secrets.yml 未正确加载。

I tried to execute bin/spring stop but no luck.我试图执行bin/spring stop但没有运气。

Is it because, secrets.yml is in gitignore?是不是因为,secrets.yml 在 gitignore 中?

I also try to remove secrets.yml from the application.我还尝试从应用程序中删除 secrets.yml。 Then open rails console again.然后再次打开 rails 控制台。 I can still see the old secrets.我仍然可以看到旧的秘密。 I changed the secrets.yml manually in the netbeans editor.我在netbeans编辑器中手动更改了 secrets.yml。

I have executed Rails.application.secrets.api_key I can see it.我已经执行了Rails.application.secrets.api_key我可以看到它。 Then using netbeans, I added 1 more key ie secret_key but I am unable to access it in rails console using Rails.application.secrets.secret_key然后使用 netbeans,我又添加了 1 个密钥,即secret_key但我无法在 Rails 控制台中使用Rails.application.secrets.secret_key访问它

I reopened the terminal several times but no luck.我重新打开了终端几次,但没有运气。

My Rails version is 5.1.4我的 Rails 版本是 5.1.4

I just restarted my computer , open terminal again and it works.我刚刚重新启动了我的电脑,再次打开终端,它就可以工作了。 Strange, I dont understand the issue but it works奇怪,我不明白这个问题,但它有效

After Rails 5.1 you can't update your secrets.yml by manually.在 Rails 5.1 之后,您无法手动更新您的 secrets.yml。 You need to first decrypt it, edit it and then encrypt again.您需要先对其进行解密、编辑,然后再次加密。 Safest way to do so is following these commands in console.最安全的方法是在控制台中执行这些命令。

First you need to run this command in your console.首先,您需要在控制台中运行此命令。 I'm not sure if it can be used by netbeans so i will write manual for vim editor, which every console can handle.我不确定它是否可以被 netbeans 使用,所以我将为 vim 编辑器编写手册,每个控制台都可以处理。

EDITOR="vim" bin/rails secrets:edit

In here you need to very careful because most of the developers having hard time using vim editor.在这里你需要非常小心,因为大多数开发人员都很难使用 vim 编辑器。

  1. Press i button按我按钮

  2. Make your changes进行更改

  3. Press escape button按退出键

  4. Then press ':' button and type wq (it should look like this :wq) and press enter然后按 ':' 按钮并输入 wq(它应该是这样的:wq)然后按回车

  5. You will see a message like this File encrypted and saved.您将看到类似此File encrypted and saved.的消息已File encrypted and saved. in your console.在您的控制台中。
  6. You can check your secrets.yml by again typing EDITOR="vim" bin/rails secrets:edit to make sure everything is updated correctly您可以通过再次输入EDITOR="vim" bin/rails secrets:edit来检查您的 secrets.yml 以确保所有内容都正确更新

Changing secrets.yml in rails 5.1+ 在 Rails 5.1+ 中更改 secrets.yml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM