Sinatra with Figaro Gem

后端 未结 1 1275
难免孤独
难免孤独 2021-01-23 09:02

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

1条回答
  •  旧巷少年郎
    2021-01-23 09:42

    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
    

    0 讨论(0)
提交回复
热议问题