简体   繁体   中英

Using ruby global value in YAML file

I am writing an app that has different parts running on multiple servers. As a result, I have a ruby file filled with global values, which contain the IP addresses of the machines on which each part is running.

The app has a Rails front end that connects to a remote database (on one of the other servers). Is it possible to make use of the ruby global variable for the sql server IP inside the database.yml file?

If it's not possible to use the ruby global in the yml file, I'm open to other suggestions for better ways to achieve what I'm trying to do (xml or something similar) - the Ruby file was only for simplicity.

Thanks in Advance

I believe that you can use ERB inside of your database.yml file.

# database.yml
<% load('path/to/globals.rb') %>
development:
  host: <%= GLOBAL_CONFIG["development_sql"] %>
  ...

However I have yet to try this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM