[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Xeno Campanoli

5/28/2008 11:25:00 PM

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?