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

X

Xeno Campanoli

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top