# YAML config files with environment specific settings

**URL:** <https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506>\
**Category:** Ruby\
**Created:** [March 21, 2009, 3:23am UTC](https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506 "2009-03-21T03:23:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin98115](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@calvin98115](https://www.ruby-forum.com/u/calvin98115)\
**Post date:** [March 21, 2009, 3:23am UTC](https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506/1 "2009-03-21T03:23:31Z")

</div>

I need to store settings by environment but started off simply with my  
config file at: \config\config.yml. The only setting I had was this:  
attachment\_volume: \attach\transfers

With this, cod I’m able to load the file within my initializer and  
reference it just fine from calling code within an ActiveRecord model  
class. So far so good.

Since this setting is a server location that varies by environment, I  
tried to use the by-environment structure and changed my config file to  
this:  
development:  
attachment\_volume: \attach\transfers

test:  
attachment\_volume: \attach\test\transfers

I get the following error during that indicates it didn’t like the  
second instance of the colon on the second line. Here is the real  
error: Uncaught exception: syntax error on line 1, col 20: `  
attachment\_volume:  
\atlas\transfer\greenlight\predevelopment\attachments’

Here is full error stack:

Exiting C:/Ruby/lib/ruby/1.8/yaml.rb:133:in `load' C:/Ruby/lib/ruby/1.8/yaml.rb:133:in`load’  
C:/Ruby/lib/ruby/1.8/yaml.rb:144:in `load_file' C:/Ruby/lib/ruby/1.8/yaml.rb:143:in`open’  
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `load_file' C:/TFS/GreenLight/DEV/server/config/initializers/load_config.rb:2 C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in`load\_without\_new\_constant\_marking’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:142:in  
`load' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in`new\_constants\_in’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:142:in  
`load' ./script/../config/../vendor/rails/railties/lib/initializer.rb:550:in`load\_application\_initializers’  
./script/…/config/…/vendor/rails/railties/lib/initializer.rb:549:in  
`each' ./script/../config/../vendor/rails/railties/lib/initializer.rb:549:i n`load\_application\_initializers’  
./script/…/config/…/vendor/rails/railties/lib/initializer.rb:167:in  
`process' ./script/../config/../vendor/rails/railties/lib/initializer.rb:112:in`send’  
./script/…/config/…/vendor/rails/railties/lib/initializer.rb:112:in  
`run' C:/TFS/GreenLight/DEV/server/config/environment.rb:16 C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
C:/Ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in`require’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:521:in  
`new_constants_in' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in`require’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/…/lib/mongrel/rails.rb:147:in  
`rails' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:113:in`cloaker\_’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in  
`call' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:149:in`listener’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel\_rails:99:in  
`cloaker_' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in`call’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/configurator.rb:50:in  
`initialize' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel_rails:84:in`new’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel\_rails:84:in  
`run' C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/lib/mongrel/command.rb:212:in`run’  
C:/Ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.5-x86-mswin32-60/bin/mongrel\_rails:281  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:142:in  
`load_without_new_constant_marking' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in`load’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:521:in  
`new_constants_in' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in`load’  
C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/servers/mongrel.rb:64  
C:/Ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`gem_original_require' C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`require’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:153:in  
`require' C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in`new\_constants\_in’  
C:/TFS/GreenLight/DEV/server/vendor/rails/activesupport/lib/active\_support/dependencies.rb:153:in  
`require' C:/TFS/GreenLight/DEV/server/vendor/rails/railties/lib/commands/server.rb:49 C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in`gem\_original\_require’  
C:/Ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:31:in  
`require' ./script/server:3 C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in`debug\_load’  
C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/lib/ruby-debug.rb:101:in  
`debug_program' C:/Ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.4.4/bin/rdebug-ide:82 C:\Ruby\bin\rdebug-ide:19:in`load’  
C:\Ruby\bin\rdebug-ide:19  
-e:2:in `load' -e:2 Uncaught exception: syntax error on line 1, col 20:`  
attachment\_volume:  
\atlas\transfer\greenlight\predevelopment\attachments’

Has anyone been able to get the by environment structure load to work?  
Please advise? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![calvin98115](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@calvin98115](https://www.ruby-forum.com/u/calvin98115)\
**Post date:** [March 21, 2009, 3:36am UTC](https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506/2 "2009-03-21T03:36:55Z")

</div>

Calvin N. wrote:

---

<div class="post-metadata">

**Author:** ![calvin98115](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@calvin98115](https://www.ruby-forum.com/u/calvin98115)\
**Post date:** [March 21, 2009, 3:38am UTC](https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506/3 "2009-03-21T03:38:06Z")

</div>

> error: Uncaught exception: syntax error on line 1, col 20: `  
> attachment\_volume:  
> \atlas\transfer\greenlight\predevelopment\attachments’

Is that a transmission error, or does \atlas really start in the first  
text  
column? directly under the ‘a’ in attachment?

Put it on the same line as volume:.

Next, in terms of style, you should use / if at all possible. MS’s  
experiment  
with \ has failed, and even their own tools respect /.

---

<div class="post-metadata">

**Author:** ![calvin98115](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ea924/32.png) [@calvin98115](https://www.ruby-forum.com/u/calvin98115)\
**Post date:** [March 21, 2009, 4:28am UTC](https://www.ruby-forum.com/t/yaml-config-files-with-environment-specific-settings/163506/4 "2009-03-21T04:28:37Z")

</div>

Phlip wrote:

> > error: Uncaught exception: syntax error on line 1, col 20: `  
> > attachment\_volume:  
> > \atlas\transfer\greenlight\predevelopment\attachments’
> 
> Is that a transmission error, or does \atlas really start in the first  
> text  
> column? directly under the ‘a’ in attachment?
> 
> Put it on the same line as volume:.
> 
> Next, in terms of style, you should use / if at all possible. MS’s  
> experiment  
> with \ has failed, and even their own tools respect /.

That’s a transmission error. Strange thing I just realized for me ( on  
windows) if i remove all whitespace, then the YAML config file load  
succeeds but my APP\_CONFIG structure that loads up is nil. Here is how  
I’m loading up my hash:  
APP\_CONFIG =  
YAML.load\_file("#{RAILS\_ROOT}/config/config.yaml")[RAILS\_ENV]

when i excecute this, the exception is thrown: self.volume =  
APP\_CONFIG[‘attachment\_volume’]  
What am I missing?
