Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

ruby on rails - database.yml &references not working

We just upgraded our virtual machines to what I thought was an identical ruby configuration (via RVM... Ruby 1.9.2, Rails 3.0.7, DataMapper 1.1.0). The biggest difference was that we went from MySQL 5.0 to 5.1.

For some reason, the exact same code/database.yml that was working on our old VMs now fails on our new ones at the point it tries to connect to the database.

The issue is that this YAML:

mysql_defaults: &mysql_defaults
  adapter: mysql
  encoding: UTF-8
  username: user
  password: pass
  host: localhost

development:
  <<: *mysql_defaults
  database: devdb

production:
  <<: *mysql_defaults
  database: productiondb
  host: master.db.site.com

Is just expanding to:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  }

Instead of:

  "mysql_defaults" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost"
  },
  "development" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"localhost",
    "database"=>"devdb"
  },
  "production" => {
    "adapter"=>"mysql",
    "encoding"=>"UTF-8",
    "username"=>"user",
    "password"=>"pass",
    "host"=>"master.db.site.com",
    "database"=>"productiondb"
  }

Anyone experienced this before?

According to Gemfile.lock (I deleted it and ran bundle install again, just for sanity's sake), all the installed dependencies are the same (i.e. the Gemfile.lock does not diff between the old and the new setup). Nor does the database.yml.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Psych is the new YAML parser which is presumably better but can't merge hash keys.

This should help http://pivotallabs.com/users/mkocher/blog/articles/1692-yaml-psych-and-ruby-1-9-2-p180-here-there-be-dragons


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...