ruby - Error when loading YAML config files in Rails -
i configuring rails mongodb, , find strange problem when paring config/mongo.yml file.
config/mongo.yml generated executing script/rails generate mongo_mapper:config, , looks following:
defaults: &defaults host: 127.0.0.1 port: 27017 development: <<: *defaults database: tc_web_development test: <<: *defaults database: tc_web_test from config file can see objects development , test should both have database field. when parsed , 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: output of puts config.inspect
{"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 not contain database attribute. when execute same statements in plain ruby console, instead of using rails console, mongo.yml parsed in 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 wondering may cause of problem. ideas? thanks.
similar question has been answered here
Comments
Post a Comment