ruby on rails connection two database

reference:
http://geekhmer.github.io/blog/2015/02/07/ruby-on-rails-connect-to-multiple-databases-and-migrations/

config/mongoid.yml
db1:
    development:
      sessions:
        default:
          database: my_person_development
          hosts:
            - localhost:27017
          options:
      options:
    production:
      sessions:
        default:
          database: my_person_production
          hosts:
            - localhost:27017
          options:
      options:
    test:
      sessions:
        default:
          database: my_person_test
          hosts:
            - localhost:27017
          options:
            read: primary
            max_retries: 1
            retry_interval: 0
db2:
    development:
      sessions:
        default:
          database: my_person_development
          hosts:
            - localhost:27017
          options:
      options:
    production:
      sessions:
        default:
          database: my_person_production
          hosts:
            - localhost:27017
          options:
      options:
    test:
      sessions:
        default:
          database: my_person_test
          hosts:
            - localhost:27017
          options:
            read: primary
            max_retries: 1
            retry_interval: 0



config/application.rb
    db_conf = YAML::load(File.open('config/mongoid.yml'))

    db1_conf = db_conf["db1"][Rails.env]
    db2_conf = db_conf["db2"][Rails.env]
    puts ENV
    puts db_conf
    puts "Hello World!!!!!!!!"
    puts db1_conf


rails s -b 0.0.0.0 --environment=production

你可能感兴趣的:(ruby on rails connection two database)