0

I saw this post and think something is missing or a change in version. I have a very simple rack app using figaro -- hosted with Heroku. Currently, Im on local machine.

I now need to use ENV.

My app structure:

APP
 |_ config/
 |_ public/
 |_ views/
 |_ config.ru
 |_ app.rb
 |_ other-files

Inside config/application.yml

SOME_KEY: some-value

Inside config.ru

require './app.rb'
run MyApp.run!

This the part this gives the error. Inside app.rb:

require  File.dirname(__FILE__) + '/config/application.yml'

[...]

This is the same line as in the link above. I get

cannot load such file /config/application.yml

In app.rb, I need to be able to do ENV['SOME_KEY']

Sylar
  • 11,422
  • 25
  • 93
  • 166

2 Answers2

1

I've done this before in a standalone app as follows:

Figaro.application = Figaro::Application.new(
  environment: 'production',
  path: File.expand_path("config/application.yml")
)
Figaro.load
mahemoff
  • 44,526
  • 36
  • 160
  • 222
0

You can't just require a yaml file as it is not ruby. Yaml is a file structure that is not ruby specific. Figaro was also written to be used with Ruby on Rails, not Sinatra. You can probably figure out a way to make it work, but it's not as easy as just loading a yaml config file.

See this post for some ideas of how you might accomplish what you're trying to do. Here is a forked version of the gem which might work for you.

https://github.com/laserlemon/figaro/pull/229

lacostenycoder
  • 10,623
  • 4
  • 31
  • 48