# Mystified by a YAML/AR interaction...?

**URL:** <https://www.ruby-forum.com/t/mystified-by-a-yaml-ar-interaction/138929>\
**Category:** Ruby\
**Created:** [May 29, 2008, 2:21am UTC](https://www.ruby-forum.com/t/mystified-by-a-yaml-ar-interaction/138929 "2008-05-29T02:21:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Xeno\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/958977/32.png) [@Xeno\_C](https://www.ruby-forum.com/u/Xeno_C)\
**Post date:** [May 29, 2008, 2:21am UTC](https://www.ruby-forum.com/t/mystified-by-a-yaml-ar-interaction/138929/1 "2008-05-29T02:21:30Z")

</div>

I’ve got the following sequence which when run interactively yields a  
working connection to my Active Record ORM where I can get data:

```
 env = 'production'
 dbymlspec = "#{RAILSBASEDIR}/config/database.yml"
 conf = YAML::load(dbymlspec)

```

STDERR.puts “trace conf: #{conf}”  
STDERR.puts “trace conf.class: #{conf.class}”  
STDERR.puts “trace conf[#{env}]: #{conf[environment]}”  
STDERR.puts “trace conf[#{env}].class: #{conf[environment].class}”  
if conf then  
ActiveRecord::Base.establish\_connection(conf[environment])  
else  
puts “YAML::load returned false on dbymlspec: #{dbymlspec}”  
end  
----snip----  
But the output to STDERR is:

trace conf: /home/rotw/bnsf/config/database.yml  
trace conf.class: String  
trace conf[production]:  
trace conf[production].class: NilClass

So the establish\_connection method shouldn’t be seeing anything but a  
nil. What’s going on here? How come establish\_connection sees the  
database, and what is the magic here?
