使用 figaro 存储环境变量

using figaro to store env variables

我对如何在 Rails 4.2 中正确使用 figaro 感到困惑。所以在 application.yml(签入 .gitignore)中,我有这个:

secret_key_base: 123456

然后在 secrets.yml 中,我有这个:

development:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

根据我读过的所有内容,gem 应该处理设置凭据的 ENV 部分。为什么这不起作用?



编辑 1: 在 application.yml 我有: mandrill_user_name: email@example.commandrill_password: 1234567890

在 development.rb 我有:

config.action_mailer.default_url_options = { :host => "localhost:3000" }

config.action_mailer.smtp_settings = {
  address: "smtp.mandrillapp.com",
  port: 587,
  domain: "localhost:3000",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["mandrill_user_name"],
  password: ENV["mandrill_password"]
}

application.yml 不应该处理这个吗?

如果在 secrets.yml 文件和 application.yml 文件中包含变量是多余的。 即仅使用 application.yml 文件来声明环境变量。

只要它在 apllication.yml 文件中,您就可以在整个 rails 应用程序中调用它,就像您正在做的那样:

ENV["SECRET_KEY_BASE"]

存储在 secrets.yml 文件中的变量通过

调用
Rails.application.secrets.SECRET_KEY_BASE