Reputation: 5511
I have a modular Sinatra app using Sinatra::ConfigFile and have broken out my settings into a yaml file so I can modify paths/urls when in different environments.
As a basic example, I have:
development:
url_root: 'http://127.0.0.1:9292'
production:
url_root: 'http://domain.com'
However, settings.url_root
does not work (undefined method 'url_root') unless I pull it out of the nested environment block. Checking my environment: p ENV['RACK_ENV']
returns development
.
I am using Sinatra 1.4.5, sinatra-contrib 1.4.2
What am I doing wrong?
Upvotes: 0
Views: 728
Reputation: 5511
OK, well it turns out it was a misunderstanding of, what I believe, is a slightly confusingly worded documentation on the Sintara page which states:
But it also can provide specific environment configuration. There are two ways to do that: at the file level and at the setting level. They are illustrated, repsectively, as follows:
development:
foo: development
bar: bar
test:
foo: test
bar: bar
production:
foo: production
bar: bar
and
foo:
development: development
test: test
production: production
bar: bar
So, when using a settings yaml file with Sinatra, you want to define the variable name and then nest the environments within it (not the other way around), and the working format for my question above is:
url_root:
development: 'http://127.0.0.1:9292'
production: 'http://domain.com'
Upvotes: 2