问题描述
我正在尝试从 config/secrets.yml
文件访问我的密钥.
I am trying to access my secret keys from the config/secrets.yml
file.
secrets.yml:
secrets.yml:
development:
secret_key_base: laksjfla...alskdfjlaksjdflaksd
other_secret: password
Rails 控制台:
$ rails c
> Rails.application.secrets
> => {:secret_key_base=>"laksjfla...alskdfjlaksjdflaksd"}
我的other_secret
在哪里?!
推荐答案
我曾经遇到过类似的问题,尝试用 bin/spring stop
重新加载 spring 服务器,因此对 secrets.yml
应该生效.然后再次运行 rails c
.(发表评论作为答案).
I've faced a similar problem once, try to reload spring server with bin/spring stop
, so the changes to secrets.yml
should take effect. then run rails c
again. (posting comment as a answer).
这里有一个开放的拉取请求 - https://github.com/rails/spring/pull/289 - 默认情况下,spring 不会监视 secrets.yml
中的更改.其中一条评论说:
There is an open pull request here - https://github.com/rails/spring/pull/289 - spring does not watch for changes in secrets.yml
by default. One of the comments says:
新版本的 gem (spring) 还没有发布,所以你可以从github 或将 Spring.watch "config/secrets.yml" 添加到您的同时配置/spring.rb
这篇关于为什么 Ruby on Rails secrets.yml 没有加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!