问题描述
我正在尝试将 Figaro gem 与 Sinatra 一起使用.我已经安装了 Figaro 并创建了以下文件/文件夹...
I m trying to use Figaro gem with Sinatra. I have installed Figaro and it created the following file/ folder...
/config/application.yml
在这个文件中,我添加了一些环境变量...
On this file I have added some environment variables...
ENV['GMAIL_USERNAME']
ENV['GMAIL_PASSWORD']
然后在我的app.rb"文件中,我试图包含 yml 文件,例如...
Then on my my "app.rb" file I am trying to include the yml file like...
require 'config/application.yml'
如何访问我的 app.rb 文件中的ENV['BIG_SECRET']"?
How can I have access to my "ENV['BIG_SECRET']" in my app.rb file?
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.gmail.com',
:port => '587',
:domain => 'mydomain.com',
:user_name => ENV['GMAIL_USERNAME'],
:password => ENV['GMAIL_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
推荐答案
您应该按照 Figaro github README https://github.com/laserlemon/figaro(在 YAML 语法中):
You should declare yuor variables in application.yml as explained at Figaro github README https://github.com/laserlemon/figaro (in YAML syntax):
pusher_app_id: "2954"
pusher_key: "7381a978f7dd7f9a1117"
pusher_secret: "abdc3b896a0ffb85d373"
test:
pusher_app_id: "5112"
pusher_key: "ad69caf9a44dcac1fb28"
pusher_secret: "83ca7aa160fedaf3b350"
...
您将能够按如下方式访问声明的变量:
You will be able to access the declared variables as follows:
ENV["stripe_api_key"] # => "sk_live_dSqzdUq80sw9GWmuoI0qJ9rL"
ENV.key?("stripe_api_key") # => true
ENV["google_analytics_key"] # => nil
ENV.key?("google_analytics_key") # => false
这篇关于辛纳屈与费加罗宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!