I am configuring Rails with MongoDB, and find a strange problem when paring config/mongo.yml file.
config/mongo.yml is generated by executing script/rails generate mongo_mapper:config, and it looks like following:
defaults: &defaults
host: 127.0.0.1
port: 27017
development:
<<: *defaults
database: tc_web_development
test:
<<: *defaults
database: tc_web_test
From the config file we can see the objects development and test should both have a database field. But when it is parsed and loaded in config/initializers/mongo.db,
config = YAML::load(File.read(Rails.root.join('config/mongo.yml')))
puts config.inspect
MongoMapper.setup(config, Rails.env)
the strange thing comes: the output of puts config.inspect is
{"defaults"=>{"host"=>"127.0.0.1", "port"=>27017}, "development"=>{"host"=>"127.0.0.1", "port"=>27017}, "test"=>{"host"=>"127.0.0.1", "port"=>27017}}
which does not contain database attribute. But when I execute the same statements in a plain ruby console, instead of using rails console, mongo.yml is parsed in a right way.
{"defaults"=>{"host"=>"127.0.0.1", "port"=>27017}, "development"=>{"host"=>"127.0.0.1", "port"=>27017, "database"=>"tc_web_development"}, "test"=>{"host"=>"127.0.0.1", "port"=>27017, "database"=>"tc_web_test"}}
I am wondering what may be the cause of this problem. Any ideas? Thanks.